package com.perforce.hws.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Common buffering and copying operations on InputStream and OutputStream
*/
public interface StreamUtils {
default byte[] readAll(InputStream is) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
copyStream(is, os);
os.flush();
return os.toByteArray();
}
default long copyStream(InputStream is, OutputStream os) throws IOException {
return copyStream(is, os, new byte[4096]);
}
default long copyStream(InputStream is, OutputStream os, byte buffer[])
throws IOException {
int readLen;
long totalCopied = 0;
while ((readLen = is.read(buffer)) != -1) {
os.write(buffer, 0, readLen);
totalCopied += readLen;
}
return totalCopied;
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
19535 |
drobins |
Refactor package names to hws |
|
|
//guest/perforce_software/helix-web-services/main/source/jdk_extensions/src/main/java/com/perforce/helix_web_services/jdk_extensions/StreamUtils.java |
#1
|
17166 |
tjuricek |
File listing and basic "modification" implementations (methods under /p4/api/files) |
|
|