Search in sources :

Example 36 with BufferedInputStream

use of java.io.BufferedInputStream in project JessMA by ldcsaa.

the class FileDownloader method downloadFile.

private void downloadFile(HttpServletRequest request, HttpServletResponse response, File file) throws IOException {
    int length = (int) file.length();
    Range<Integer> range = prepareDownload(request, response, length);
    InputStream is = new BufferedInputStream(new FileInputStream(file));
    doDownload(response, is, range);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream)

Example 37 with BufferedInputStream

use of java.io.BufferedInputStream in project languagetool by languagetool-org.

the class Main method getInputStreamReader.

private InputStreamReader getInputStreamReader(String filename, String encoding) throws IOException {
    String charsetName = encoding != null ? encoding : Charset.defaultCharset().name();
    InputStream is = System.in;
    if (!isStdIn(filename)) {
        is = new FileInputStream(new File(filename));
        BOMInputStream bomIn = new BOMInputStream(is, true, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE);
        if (bomIn.hasBOM() && encoding == null) {
            charsetName = bomIn.getBOMCharsetName();
        }
        is = bomIn;
    }
    return new InputStreamReader(new BufferedInputStream(is), charsetName);
}
Also used : BOMInputStream(org.apache.commons.io.input.BOMInputStream) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) BOMInputStream(org.apache.commons.io.input.BOMInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StringTools.readerToString(org.languagetool.tools.StringTools.readerToString) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 38 with BufferedInputStream

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

the class JarUtils method createJarFile.

public static File createJarFile(final String name, final Suffix s, final String base, final Map<String, String> entries) throws IOException {
    final File tempJar = File.createTempFile(name, "." + s);
    tempJar.deleteOnExit();
    final JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)), new Manifest());
    final Set<String> usedSegments = new HashSet<String>();
    for (final Map.Entry<String, String> entry : entries.entrySet()) {
        for (final String path : getPaths(entry.getValue())) {
            if (usedSegments.contains(path)) {
                continue;
            }
            usedSegments.add(path);
            final JarEntry e = new JarEntry(path);
            jos.putNextEntry(e);
            jos.closeEntry();
        }
        final JarEntry e = new JarEntry(entry.getValue());
        jos.putNextEntry(e);
        final InputStream f = new BufferedInputStream(new FileInputStream(base + entry.getKey()));
        final byte[] buf = new byte[1024];
        int read = 1024;
        while ((read = f.read(buf, 0, read)) != -1) {
            jos.write(buf, 0, read);
        }
        jos.closeEntry();
    }
    jos.close();
    return tempJar;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) JarEntry(java.util.jar.JarEntry) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 39 with BufferedInputStream

use of java.io.BufferedInputStream in project k-9 by k9mail.

the class ImapConnection method setUpStreamsAndParser.

private void setUpStreamsAndParser(InputStream input, OutputStream output) {
    inputStream = new PeekableInputStream(new BufferedInputStream(input, BUFFER_SIZE));
    responseParser = new ImapResponseParser(inputStream);
    outputStream = new BufferedOutputStream(output, BUFFER_SIZE);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) PeekableInputStream(com.fsck.k9.mail.filter.PeekableInputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 40 with BufferedInputStream

use of java.io.BufferedInputStream in project hbase by apache.

the class Base64 method decodeFromFile.

// end decodeToFile
/**
   * Convenience method for reading a base64-encoded file and decoding it.
   *
   * @param filename Filename for reading encoded data
   * @return decoded byte array or null if unsuccessful
   *
   * @since 2.1
   */
public static byte[] decodeFromFile(String filename) {
    byte[] decodedData = null;
    BufferedInputStream bufferedInputStream = null;
    FileInputStream fileInputStream = null;
    Base64InputStream base64InputStream = null;
    try {
        File file = new File(filename);
        byte[] buffer;
        // Check the size of file
        if (file.length() > Integer.MAX_VALUE) {
            LOG.fatal("File is too big for this convenience method (" + file.length() + " bytes).");
            return null;
        }
        // end if: file too big for int index
        buffer = new byte[(int) file.length()];
        // Open a stream
        fileInputStream = new FileInputStream(file);
        bufferedInputStream = new BufferedInputStream(fileInputStream);
        base64InputStream = new Base64InputStream(bufferedInputStream, DECODE);
        // Read until done
        int length = 0;
        for (int numBytes; (numBytes = base64InputStream.read(buffer, length, 4096)) >= 0; ) {
            length += numBytes;
        }
        // Save in a variable to return
        decodedData = new byte[length];
        System.arraycopy(buffer, 0, decodedData, 0, length);
    } catch (IOException e) {
        LOG.error("Error decoding from file " + filename, e);
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (Exception e) {
                LOG.error("error closing FileInputStream", e);
            }
        }
        if (bufferedInputStream != null) {
            try {
                bufferedInputStream.close();
            } catch (Exception e) {
                LOG.error("error closing BufferedInputStream", e);
            }
        }
        if (base64InputStream != null) {
            try {
                base64InputStream.close();
            } catch (Exception e) {
                LOG.error("error closing Base64InputStream", e);
            }
        }
    }
    return decodedData;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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