List of usage examples for java.io BufferedInputStream BufferedInputStream
public BufferedInputStream(InputStream in)
BufferedInputStream
and saves its argument, the input stream in
, for later use. From source file:edu.vt.middleware.crypt.util.CryptReader.java
/** * Reads the raw bytes of a symmetric encryption key from a file. * * @param keyFile File containing key data. * @param algorithm Symmetric cipher algorithm for which key is used. * * @return Secret key./* www . jav a2s .c o m*/ * * @throws IOException On IO errors. */ public static SecretKey readSecretKey(final File keyFile, final String algorithm) throws IOException { return readSecretKey(new BufferedInputStream(new FileInputStream(keyFile)), algorithm); }
From source file:be.roots.taconic.pricingguide.util.HttpUtil.java
public static byte[] readByteArray(String urlAsString, String userName, String password) { try {//w w w . j a v a 2 s.c om final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password); final BufferedInputStream in = new BufferedInputStream(con.getInputStream()); final byte[] response = IOUtils.toByteArray(in); IOUtils.closeQuietly(in); return response; } catch (IOException e) { LOGGER.error(e.getLocalizedMessage(), e); } return null; }
From source file:com.machinelinking.util.FileUtil.java
public static BufferedInputStream openDecompressedInputStream(InputStream is, String ext) throws IOException { final InputStream decompressInputStream; switch (ext) { case "gz": decompressInputStream = new GZIPInputStream(is); break;//from w w w. j a v a2 s .c o m case "bz2": decompressInputStream = new BZip2CompressorInputStream(is); break; default: throw new IllegalArgumentException("Unsupported extension: " + ext); } return new BufferedInputStream(decompressInputStream); }
From source file:com.mebigfatguy.inventory.core.Inventory.java
public Inventory(File archive) throws IOException { this.archive = archive; stream = new BufferedInputStream(new FileInputStream(archive)); listeners = new HashSet<>(); }
From source file:SendMp3.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fileName = (String) request.getParameter("file"); if (fileName == null || fileName.equals("")) throw new ServletException("Invalid or non-existent file parameter in SendMp3 servlet."); if (fileName.indexOf(".mp3") == -1) fileName = fileName + ".mp3"; String mp3Dir = getServletContext().getInitParameter("mp3-dir"); if (mp3Dir == null || mp3Dir.equals("")) throw new ServletException("Invalid or non-existent mp3Dir context-param."); ServletOutputStream stream = null;/* w w w. j ava2s. c om*/ BufferedInputStream buf = null; try { stream = response.getOutputStream(); File mp3 = new File(mp3Dir + "/" + fileName); //set response headers response.setContentType("audio/mpeg"); response.addHeader("Content-Disposition", "attachment; filename=" + fileName); response.setContentLength((int) mp3.length()); FileInputStream input = new FileInputStream(mp3); buf = new BufferedInputStream(input); int readBytes = 0; //read from the file; write to the ServletOutputStream while ((readBytes = buf.read()) != -1) stream.write(readBytes); } catch (IOException ioe) { throw new ServletException(ioe.getMessage()); } finally { if (stream != null) stream.close(); if (buf != null) buf.close(); } }
From source file:com.mesosphere.dcos.cassandra.executor.compress.SnappyCompressionDriver.java
@Override public void compress(final String sourcePath, final String destinationPath) throws IOException { BufferedInputStream inputStream = null; SnappyOutputStream compressedStream = null; try {// w w w . j a v a 2s. c o m inputStream = new BufferedInputStream(new FileInputStream(sourcePath)); compressedStream = new SnappyOutputStream( new BufferedOutputStream(new FileOutputStream(destinationPath))); IOUtils.copy(inputStream, compressedStream); } catch (IOException e) { LOGGER.error("Failed to compress {} to {} due to: {}", sourcePath, destinationPath, e); } finally { IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(compressedStream); } }
From source file:com.mycompany.cassandrajavaclient.XmlParser.java
private void parse(String xmlContent) { try {/* w w w . j a v a 2 s . c om*/ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); try { InputStream inputStream = new BufferedInputStream( new ReaderInputStream(new StringReader(xmlContent))); final Document document = builder.parse(inputStream); emit(document); } catch (SAXException | IOException ex) { Logger.getLogger(XmlParser.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParserConfigurationException ex) { Logger.getLogger(XmlParser.class.getName()).log(Level.SEVERE, null, ex); } }