private static void fileChunking() throws IOException {
InputStream is = null;
OutputStream os = null;
byte[] buffer;
int maxBufferSize = 102400;
int bytesRead, bytesAvailable, bufferSize;
int responsecode = 0;
String responsemessage = null;
bufferSize = Math.min(content.length, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = is.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
os.write(buffer, 0, bufferSize);
bytesAvailable = is.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = is.read(buffer, 0, bufferSize);
}
is.close();
os.flush();
responsecode = con.getResponseCode();
responsemessage = con.getResponseMessage();
System.out.print(responsemessage);
}
コードは、bytesRead = is.read(buffer, 0, bufferSize); の読み取り中に「Stream already open」という例外をスローします。