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:com.dubture.symfony.core.util.UncompressUtils.java
/** * Uncompress a gzip archive and returns the file where it has been * extracted.// w w w. jav a 2 s .c o m * * @param archiveFile The archive file to uncompress * @param outputDirectory The output directory where to put the uncompressed archive * * @return The output file where the archive has been uncompressed * * @throws IOException When a problem occurs with either the input or output stream */ public static File uncompressGzipArchive(File archiveFile, File outputDirectory) throws IOException { FileInputStream fileInputStream = new FileInputStream(archiveFile); BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream); GzipCompressorInputStream gzipInputStream = new GzipCompressorInputStream(bufferedInputStream); String tarArchiveFilename = GzipUtils.getUncompressedFilename(archiveFile.getName()); File outputFile = new File(outputDirectory, tarArchiveFilename); FileOutputStream outputStream = new FileOutputStream(outputFile); int byteReadCount = 0; final byte[] data = new byte[BUFFER_SIZE]; try { while ((byteReadCount = gzipInputStream.read(data, 0, BUFFER_SIZE)) != -1) { outputStream.write(data, 0, byteReadCount); } } finally { outputStream.close(); gzipInputStream.close(); } return outputFile; }
From source file:io.cloudslang.orchestrator.services.ExecutionSerializationUtil.java
public Execution objFromBytes(byte[] bytes) { ObjectInputStream ois = null; try {// w w w. jav a 2 s. c o m //2 Buffers are added to increase performance ByteArrayInputStream is = new ByteArrayInputStream(bytes); BufferedInputStream bis = new BufferedInputStream(is); ois = new ObjectInputStream(bis); //noinspection unchecked return (Execution) ois.readObject(); } catch (IOException | ClassNotFoundException ex) { throw new RuntimeException("Failed to read execution from byte[]. Error: ", ex); } finally { IOUtils.closeQuietly(ois); } }
From source file:de.flapdoodle.embed.process.extract.TxzExtractor.java
protected ArchiveWrapper archiveStream(File source) throws IOException { FileInputStream fin = new FileInputStream(source); BufferedInputStream in = new BufferedInputStream(fin); XZCompressorInputStream gzIn = new XZCompressorInputStream(in); TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); return new TarArchiveWrapper(tarIn); }
From source file:com.manning.androidhacks.hack037.MediaUtils.java
public static void saveRaw(Context context, int raw, String path) { File completePath = new File(Environment.getExternalStorageDirectory(), path); try {// w ww . ja v a 2s .c o m completePath.getParentFile().mkdirs(); completePath.createNewFile(); BufferedOutputStream bos = new BufferedOutputStream((new FileOutputStream(completePath))); BufferedInputStream bis = new BufferedInputStream(context.getResources().openRawResource(raw)); byte[] buff = new byte[32 * 1024]; int len; while ((len = bis.read(buff)) > 0) { bos.write(buff, 0, len); } bos.flush(); bos.close(); } catch (IOException io) { Log.e(TAG, "Error: " + io); } }
From source file:SwingResourceManager.java
/** * Returns an image stored in the file at the specified path relative to the specified class * @param clazz Class The class relative to which to find the image * @param path String The path to the image file * @return Image The image stored in the file at the specified path *//*from w w w . j a v a 2 s. c o m*/ public static Image getImage(Class<?> clazz, String path) { String key = clazz.getName() + '|' + path; Image image = m_ClassImageMap.get(key); if (image == null) { if ((path.length() > 0) && (path.charAt(0) == '/')) { String newPath = path.substring(1, path.length()); image = getImage(new BufferedInputStream(clazz.getClassLoader().getResourceAsStream(newPath))); } else { image = getImage(clazz.getResourceAsStream(path)); } m_ClassImageMap.put(key, image); } return image; }
From source file:com.mtt.myapp.common.util.FileDownloadUtil.java
/** * Provide file download from the given file path. * @param response {@link javax.servlet.http.HttpServletResponse} * @param desFile file path/*from ww w.j av a2s .c o m*/ * @return true if succeeded */ public static boolean downloadFile(HttpServletResponse response, File desFile) { if (desFile == null || !desFile.exists()) { return false; } boolean result = true; response.reset(); response.addHeader("Content-Disposition", "attachment;filename=" + desFile.getName()); response.setContentType("application/octet-stream"); response.addHeader("Content-Length", "" + desFile.length()); InputStream fis = null; byte[] buffer = new byte[FILE_DOWNLOAD_BUFFER_SIZE]; OutputStream toClient = null; try { fis = new BufferedInputStream(new FileInputStream(desFile)); toClient = new BufferedOutputStream(response.getOutputStream()); int readLength; while (((readLength = fis.read(buffer)) != -1)) { toClient.write(buffer, 0, readLength); } toClient.flush(); } catch (FileNotFoundException e) { LOGGER.error("file not found:" + desFile.getAbsolutePath(), e); result = false; } catch (IOException e) { LOGGER.error("read file error:" + desFile.getAbsolutePath(), e); result = false; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(toClient); } return result; }
From source file:com.splout.db.benchmark.TCPTest.java
public static void tcpTest(String file, String table) throws UnknownHostException, IOException, InterruptedException, JSONSerDeException { final TCPServer server = new TCPServer(8888, file, table); Thread t = new Thread() { @Override//from w w w. j a va2 s . c o m public void run() { server.serve(); } }; t.start(); while (!server.isServing()) { Thread.sleep(100); } Socket clientSocket = new Socket("localhost", 8888); DataInputStream inFromServer = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())); try { do { // Read a record inFromServer.readUTF(); inFromServer.readInt(); inFromServer.readDouble(); inFromServer.readUTF(); } while (true); } catch (Throwable th) { th.printStackTrace(); } clientSocket.close(); server.stop(); t.interrupt(); }
From source file:com.sangupta.shire.config.PropertyConfigReader.java
@Override protected Properties readFile(File configFile) throws IOException { Properties properties = new Properties(); properties.load(new BufferedInputStream(new FileInputStream(configFile))); return properties; }
From source file:com.googlecode.pondskum.client.listener.FileWritingConnectionListener.java
private static List<String> dumpContent(final InputStream incoming) throws IOException { InputStream in = new BufferedInputStream(incoming); int content;/*w ww.j a va 2s . co m*/ StringBuilder sb = new StringBuilder(); while ((content = in.read()) != -1) { sb.append((char) content); } return Arrays.asList(sb.toString()); }
From source file:eu.aniketos.ncvm.impl.EncodeSupport.java
/** * This methods read a file into a string. * //from w w w. ja v a 2s. c o m * @param filePath * Path of the text file that should be read. * @return File content as string. */ static String readFileAsString(String filePath) throws java.io.IOException { int fileSize = (int) new File(filePath).length(); byte[] buffer = new byte[fileSize]; BufferedInputStream f = null; try { FileInputStream inputStream = new FileInputStream(filePath); f = new BufferedInputStream(inputStream); f.read(buffer); } finally { if (f != null) try { f.close(); } catch (IOException ignored) { } } return new String(buffer); }