Search in sources :

Example 11 with BufferedInputStream

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);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 12 with BufferedInputStream

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) Hashtable(java.util.Hashtable) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 13 with BufferedInputStream

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 14 with BufferedInputStream

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);
}
Also used : FileSnap(org.apache.zookeeper.server.persistence.FileSnap) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) CheckedInputStream(java.util.zip.CheckedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InputArchive(org.apache.jute.InputArchive) BinaryInputArchive(org.apache.jute.BinaryInputArchive) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream) Adler32(java.util.zip.Adler32)

Example 15 with BufferedInputStream

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);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) FileInputStream(java.io.FileInputStream) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)3306 IOException (java.io.IOException)1660 FileInputStream (java.io.FileInputStream)1550 InputStream (java.io.InputStream)1473 File (java.io.File)886 BufferedOutputStream (java.io.BufferedOutputStream)499 FileOutputStream (java.io.FileOutputStream)467 ByteArrayInputStream (java.io.ByteArrayInputStream)330 URL (java.net.URL)298 FileNotFoundException (java.io.FileNotFoundException)273 DataInputStream (java.io.DataInputStream)263 OutputStream (java.io.OutputStream)253 ZipEntry (java.util.zip.ZipEntry)248 ByteArrayOutputStream (java.io.ByteArrayOutputStream)237 ArrayList (java.util.ArrayList)148 ZipInputStream (java.util.zip.ZipInputStream)143 GZIPInputStream (java.util.zip.GZIPInputStream)135 InputStreamReader (java.io.InputStreamReader)132 HttpURLConnection (java.net.HttpURLConnection)119 HashMap (java.util.HashMap)119