You can simply use a for loop (it is still duplicating some code though):
OutputStream os = ...;
InputStream is = ...;
byte[] buffer = new byte[1024];
for (int bufferLength = is.read(buffer); bufferLength != -1; bufferLength = is.read(buffer)) {
os.write(buffer, 0, bufferLength);
}