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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations