How I can download issue attachments from JIRA using java code ?

import java.util.Iterator;

// Get details of a given JIRA Issue
public class Test3
{
public static void main(String args) throws IOException
{

URI jiraServerUri = URI.create(“http://localhost:8080”);

AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();

JiraRestClient restClient = factory.create(jiraServerUri, new BasicHttpAuthenticationHandler(“user”, “password”));
IssueRestClient issueClient = restClient.getIssueClient();

try
{
Issue issue = issueClient.getIssue(“DEMO-123”).claim();

Iterator<BasicComponent> allComponents = issue.getComponents().iterator();
while (allComponents.hasNext())
{
BasicComponent component = allComponents.next();
System.out.println("Component : " + component.getName());
}

Iterator<String> allLabels = issue.getLabels().iterator();
while (allLabels.hasNext())
{

Iterator<Attachment> attachments = issue.getAttachments().iterator();
while (attachments.hasNext())
{
Attachment attachment = attachments.next();
System.out.println("Attachment : " + attachment.getFilename());
}
} finally {
restClient.close();
}

}
}

I am getting the attachment name from this code but how can I download the attachment in my local machine ?

Look at the AttachmentManager class and especially AttachmentManager.streamAttachmentContent().