use of java.io.BufferedInputStream in project deeplearning4j by deeplearning4j.
the class ConnectionCosts method read.
private static ConnectionCosts read(InputStream input) throws IOException {
DataInputStream dataInput = new DataInputStream(new BufferedInputStream(input));
int size = dataInput.readInt();
ByteBuffer byteBuffer = ByteBufferIO.read(dataInput);
ShortBuffer costs = byteBuffer.asShortBuffer();
return new ConnectionCosts(size, costs);
}
use of java.io.BufferedInputStream in project che by eclipse.
the class DeltaProcessingState method getExternalLibTimeStamps.
public Hashtable getExternalLibTimeStamps() {
if (this.externalTimeStamps == null) {
Hashtable timeStamps = new Hashtable();
File timestampsFile = getTimeStampsFile();
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(timestampsFile)));
int size = in.readInt();
while (size-- > 0) {
String key = in.readUTF();
long timestamp = in.readLong();
timeStamps.put(Path.fromPortableString(key), new Long(timestamp));
}
} catch (IOException e) {
if (timestampsFile.exists())
//$NON-NLS-1$
Util.log(e, "Unable to read external time stamps");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// nothing we can do: ignore
}
}
}
this.externalTimeStamps = timeStamps;
}
return this.externalTimeStamps;
}
use of java.io.BufferedInputStream in project tomcat by apache.
the class DefaultServlet method copy.
/**
* Copy the contents of the specified input stream to the specified
* output stream, and ensure that both streams are closed before returning
* (even in the face of an exception).
*
* @param resource The source resource
* @param ostream The output stream to write to
* @param ranges Enumeration of the ranges the client wanted to
* retrieve
* @param contentType Content type of the resource
* @exception IOException if an input/output error occurs
*/
protected void copy(WebResource resource, ServletOutputStream ostream, Iterator<Range> ranges, String contentType) throws IOException {
IOException exception = null;
while ((exception == null) && (ranges.hasNext())) {
InputStream resourceInputStream = resource.getInputStream();
try (InputStream istream = new BufferedInputStream(resourceInputStream, input)) {
Range currentRange = ranges.next();
// Writing MIME header.
ostream.println();
ostream.println("--" + mimeSeparation);
if (contentType != null)
ostream.println("Content-Type: " + contentType);
ostream.println("Content-Range: bytes " + currentRange.start + "-" + currentRange.end + "/" + currentRange.length);
ostream.println();
// Printing content
exception = copyRange(istream, ostream, currentRange.start, currentRange.end);
}
}
ostream.println();
ostream.print("--" + mimeSeparation + "--");
// Rethrow any exception that has occurred
if (exception != null)
throw exception;
}
use of java.io.BufferedInputStream in project zookeeper by apache.
the class SnapshotFormatter method run.
public void run(String snapshotFileName) throws IOException {
InputStream is = new CheckedInputStream(new BufferedInputStream(new FileInputStream(snapshotFileName)), new Adler32());
InputArchive ia = BinaryInputArchive.getArchive(is);
FileSnap fileSnap = new FileSnap(null);
DataTree dataTree = new DataTree();
Map<Long, Integer> sessions = new HashMap<Long, Integer>();
fileSnap.deserialize(dataTree, sessions, ia);
printDetails(dataTree, sessions);
}
use of java.io.BufferedInputStream in project cw-omnibus by commonsguy.
the class ZipUtils method unzip.
public static void unzip(File zipFile, File destDir, String subtreeInZip) throws UnzipException, IOException {
if (destDir.exists()) {
deleteContents(destDir);
} else {
destDir.mkdirs();
}
try {
final FileInputStream fis = new FileInputStream(zipFile);
final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
int entries = 0;
long total = 0;
try {
while ((entry = zis.getNextEntry()) != null) {
if (subtreeInZip == null || entry.getName().startsWith(subtreeInZip)) {
int bytesRead;
final byte[] data = new byte[BUFFER_SIZE];
final String zipCanonicalPath = validateZipEntry(entry.getName().substring(subtreeInZip.length()), destDir);
if (entry.isDirectory()) {
new File(zipCanonicalPath).mkdir();
} else {
final FileOutputStream fos = new FileOutputStream(zipCanonicalPath);
final BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE);
while (total + BUFFER_SIZE <= DEFAULT_MAX_SIZE && (bytesRead = zis.read(data, 0, BUFFER_SIZE)) != -1) {
dest.write(data, 0, bytesRead);
total += bytesRead;
}
dest.flush();
fos.getFD().sync();
dest.close();
if (total + BUFFER_SIZE > DEFAULT_MAX_SIZE) {
throw new IllegalStateException("Too much output from ZIP");
}
}
zis.closeEntry();
entries++;
if (entries > DEFAULT_MAX_ENTRIES) {
throw new IllegalStateException("Too many entries in ZIP");
}
}
}
} finally {
zis.close();
}
} catch (Throwable t) {
if (destDir.exists()) {
delete(destDir);
}
throw new UnzipException("Problem in unzip operation, rolling back", t);
}
}
Aggregations