Search in sources :

Example 71 with BufferedInputStream

use of java.io.BufferedInputStream in project love-android by hagish.

the class LoveZip method zipPeekHasFileName.

/// warning, might be slow, shouldn't be used for every file access
private static boolean zipPeekHasFileName(File f, String sSearchFileName) {
    //~ LoveVM.LoveLog(TAG,"zipPeekHasFileName path='"+f.getPath()+"' search='"+sSearchFileName+"'");
    try {
        InputStream is = new FileInputStream(f);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is, 8 * 1024));
        try {
            ZipEntry ze;
            while ((ze = zis.getNextEntry()) != null) {
                String filename = ze.getName();
                //~ LoveVM.LoveLog(TAG,"zipPeekHasFileName filename='"+filename+"'");
                if (filename.equals(sSearchFileName))
                    return true;
            }
        } finally {
            zis.close();
        }
    } catch (IOException e) {
        LoveVM.LoveLogE(TAG, "zipPeekHasFileName:failed to open file", e);
    }
    return false;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 72 with BufferedInputStream

use of java.io.BufferedInputStream in project hazelcast by hazelcast.

the class PhoneHome method fetchWebService.

private void fetchWebService(String urlStr) {
    InputStream in = null;
    try {
        URL url = new URL(urlStr);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("User-Agent", "Mozilla/5.0");
        conn.setConnectTimeout(TIMEOUT * 2);
        conn.setReadTimeout(TIMEOUT * 2);
        in = new BufferedInputStream(conn.getInputStream());
    } catch (IOException ignored) {
        EmptyStatement.ignore(ignored);
    } finally {
        IOUtil.closeResource(in);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 73 with BufferedInputStream

use of java.io.BufferedInputStream in project caffeine by ben-manes.

the class AbstractTraceReader method readFile.

/** Returns the input stream, decompressing if required. */
private InputStream readFile(String filePath) throws IOException {
    BufferedInputStream input = new BufferedInputStream(openFile(filePath), BUFFER_SIZE);
    input.mark(100);
    try {
        return new XZInputStream(input);
    } catch (IOException e) {
        input.reset();
    }
    try {
        return new CompressorStreamFactory().createCompressorInputStream(input);
    } catch (CompressorException e) {
        input.reset();
    }
    try {
        return new ArchiveStreamFactory().createArchiveInputStream(input);
    } catch (ArchiveException e) {
        input.reset();
    }
    return input;
}
Also used : ArchiveStreamFactory(org.apache.commons.compress.archivers.ArchiveStreamFactory) XZInputStream(org.tukaani.xz.XZInputStream) BufferedInputStream(java.io.BufferedInputStream) CompressorException(org.apache.commons.compress.compressors.CompressorException) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) IOException(java.io.IOException) ArchiveException(org.apache.commons.compress.archivers.ArchiveException)

Example 74 with BufferedInputStream

use of java.io.BufferedInputStream in project coursera-android by aporter.

the class ExternalFileWriteReadActivity method copyImageToMemory.

private void copyImageToMemory(File outFile) {
    try {
        BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(outFile));
        BufferedInputStream is = new BufferedInputStream(getResources().openRawResource(R.raw.painter));
        copy(is, os);
    } catch (FileNotFoundException e) {
        Log.e(TAG, "FileNotFoundException");
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 75 with BufferedInputStream

use of java.io.BufferedInputStream in project bazel by bazelbuild.

the class AndroidResourceValidatorAction method unpackZip.

private static void unpackZip(Path mergedResources, Path expandedOut) throws IOException {
    byte[] buffer = new byte[4096];
    try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(mergedResources)))) {
        ZipEntry z = zis.getNextEntry();
        while (z != null) {
            String entryName = z.getName();
            Path outputPath = expandedOut.resolve(entryName);
            Files.createDirectories(outputPath.getParent());
            try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(outputPath))) {
                int count = zis.read(buffer);
                while (count != -1) {
                    out.write(buffer, 0, count);
                    count = zis.read(buffer);
                }
            }
            z = zis.getNextEntry();
        }
    }
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1700 FileInputStream (java.io.FileInputStream)854 IOException (java.io.IOException)836 InputStream (java.io.InputStream)707 File (java.io.File)449 BufferedOutputStream (java.io.BufferedOutputStream)228 FileOutputStream (java.io.FileOutputStream)218 DataInputStream (java.io.DataInputStream)168 ByteArrayInputStream (java.io.ByteArrayInputStream)159 FileNotFoundException (java.io.FileNotFoundException)147 URL (java.net.URL)147 ZipEntry (java.util.zip.ZipEntry)123 ByteArrayOutputStream (java.io.ByteArrayOutputStream)112 OutputStream (java.io.OutputStream)100 ZipInputStream (java.util.zip.ZipInputStream)72 GZIPInputStream (java.util.zip.GZIPInputStream)68 ArrayList (java.util.ArrayList)62 HashMap (java.util.HashMap)62 HttpURLConnection (java.net.HttpURLConnection)61 ObjectInputStream (java.io.ObjectInputStream)56