com.taskadapter.redmineapi.internal.CopyBytesHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redmine-java-api Show documentation
Show all versions of redmine-java-api Show documentation
Free open-source Java API for Redmine and Chiliproject bug/task management systems.
This project was originally a part of Task Adapter application (http://www.taskadapter.com)
and then was open-sourced.
The newest version!
package com.taskadapter.redmineapi.internal;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.taskadapter.redmineapi.RedmineCommunicationException;
import com.taskadapter.redmineapi.RedmineException;
import com.taskadapter.redmineapi.internal.comm.BasicHttpResponse;
import com.taskadapter.redmineapi.internal.comm.ContentHandler;
public final class CopyBytesHandler implements ContentHandler {
private final OutputStream outStream;
public CopyBytesHandler(OutputStream outStream) {
this.outStream = outStream;
}
@Override
public Void processContent(BasicHttpResponse content)
throws RedmineException {
final byte[] buffer = new byte[4096 * 4];
int numberOfBytesRead;
try {
try (InputStream input = content.getStream()) {
while ((numberOfBytesRead = input.read(buffer)) > 0)
outStream.write(buffer, 0, numberOfBytesRead);
}
} catch (IOException e) {
throw new RedmineCommunicationException(e);
}
return null;
}
}