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:LabelJarSample.java
public static Image getImage(Class relativeClass, String filename) { Image returnValue = null;// w w w .ja va 2 s . c om InputStream is = relativeClass.getResourceAsStream(filename); if (is != null) { BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int ch; while ((ch = bis.read()) != -1) { baos.write(ch); } returnValue = Toolkit.getDefaultToolkit().createImage(baos.toByteArray()); } catch (IOException exception) { System.err.println("Error loading: " + filename); } } return returnValue; }
From source file:net.landora.video.info.file.FileHasher.java
public static String getED2KHash(File file) { InputStream is = null;//from w w w . j a v a 2 s. c o m try { is = new BufferedInputStream(new FileInputStream(file)); Edonkey e2dkChecksum = new Edonkey(); IOUtils.copy(is, new CheckedOutputStream(new NullOutputStream(), e2dkChecksum)); return e2dkChecksum.getHexValue(); } catch (Exception e) { LoggerFactory.getLogger(FileHasher.class).error("Error hashing file.", e); return null; } finally { IOUtils.closeQuietly(is); } }
From source file:edu.harvard.i2b2.eclipse.plugins.metadataLoader.util.FileUtil.java
public static void unzip(String zipname) throws IOException { FileInputStream fis = new FileInputStream(zipname); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); //?? GZIPInputStream gzis = new GZIPInputStream(new BufferedInputStream(fis)); // get directory of the zip file if (zipname.contains("\\")) zipname = zipname.replace("\\", "/"); // String zipDirectory = zipname.substring(0, zipname.lastIndexOf("/")+1) ; String zipDirectory = zipname.substring(0, zipname.lastIndexOf(".")); new File(zipDirectory).mkdir(); RunData.getInstance().setMetadataDirectory(zipDirectory); ZipEntry entry;//w ww . j a v a 2s . c om while ((entry = zis.getNextEntry()) != null) { System.out.println("Unzipping: " + entry.getName()); if (entry.getName().contains("metadata")) { RunData.getInstance().setMetadataFile(zipDirectory + "/" + entry.getName()); } else if (entry.getName().contains("schemes")) { RunData.getInstance().setSchemesFile(zipDirectory + "/" + entry.getName()); } else if (entry.getName().contains("access")) { RunData.getInstance().setTableAccessFile(zipDirectory + "/" + entry.getName()); } int size; byte[] buffer = new byte[2048]; FileOutputStream fos = new FileOutputStream(zipDirectory + "/" + entry.getName()); BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length); while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); } zis.close(); fis.close(); }
From source file:net.ovres.util.UncompressedInputStream.java
/** * Returns a decompressed version of the given input stream. * This is done for any set //from w w w . j a v a 2s. c o m * * @param raw the raw input stream * @return the decompressed version of <tt>raw</tt> */ public static InputStream convertStream(InputStream raw) throws IOException { if (!raw.markSupported()) { raw = new BufferedInputStream(raw); } try { return new CompressorStreamFactory().createCompressorInputStream(raw); } catch (CompressorException e) { // Assume this is because of an unknown compression type. // That's ok, it might not be compressed. return raw; } }
From source file:Main.java
static private void addFileToZip(String path, File srcFile, ZipOutputStream zip, String destZipFile) throws Exception { if (srcFile.isDirectory()) { addFolderToZip(path, srcFile, zip, destZipFile); } else if (!srcFile.getName().equals(destZipFile)) { byte[] buf = new byte[1024]; int len;//from w ww .j av a 2s .com final InputStream in = new BufferedInputStream(new FileInputStream(srcFile)); try { if (path.equals("/")) { zip.putNextEntry(new ZipEntry(srcFile.getName())); } else { zip.putNextEntry(new ZipEntry(path + "/" + srcFile.getName())); } while ((len = in.read(buf)) > 0) { zip.write(buf, 0, len); } } finally { in.close(); } } }
From source file:Main.java
@SuppressLint("NewApi") public static void getURL(String path) { String fileName = ""; String dir = "/IndoorNavi/"; File sdRoot = Environment.getExternalStorageDirectory(); try {/*from w w w .jav a2 s .co m*/ // Open the URLConnection for reading URL u = new URL(path); // URL u = new URL("http://www.baidu.com/"); HttpURLConnection uc = (HttpURLConnection) u.openConnection(); int code = uc.getResponseCode(); String response = uc.getResponseMessage(); //System.out.println("HTTP/1.x " + code + " " + response); for (int j = 1;; j++) { String key = uc.getHeaderFieldKey(j); String header = uc.getHeaderField(j); if (!(key == null)) { if (key.equals("Content-Name")) fileName = header; } if (header == null || key == null) break; //System.out.println(uc.getHeaderFieldKey(j) + ": " + header); } Log.i("zhr", fileName); //System.out.println(); try (InputStream in = new BufferedInputStream(uc.getInputStream())) { // chain the InputStream to a Reader Reader r = new InputStreamReader(in); int c; File mapFile = new File(sdRoot, dir + fileName); mapFile.createNewFile(); FileOutputStream filecon = new FileOutputStream(mapFile); while ((c = r.read()) != -1) { //System.out.print((char) c); filecon.write(c); filecon.flush(); } filecon.close(); } } catch (MalformedURLException ex) { System.err.println(path + " is not a parseable URL"); } catch (IOException ex) { System.err.println(ex); } }
From source file:Main.java
public static void copyInputToFile(InputStream in, String path) { BufferedInputStream bis = null; FileOutputStream fos = null;/*from www . ja v a 2 s . c o m*/ try { byte[] buffer = new byte[10 * 1024]; bis = new BufferedInputStream(in); fos = new FileOutputStream(path); int a = bis.read(buffer, 0, buffer.length); while (a != -1) { fos.write(buffer, 0, a); fos.flush(); a = bis.read(buffer, 0, buffer.length); } } catch (Exception e) { e.printStackTrace(); } finally { closeOutputStream(fos); closeInputStream(bis); closeInputStream(in); } }
From source file:br.com.manish.ahy.kernel.util.FileUtil.java
public static String readFileAsString(String path) { String ret = null;/*from w ww . j a v a 2 s . co m*/ try { byte[] buffer = new byte[(int) new File(path).length()]; BufferedInputStream f = new BufferedInputStream(new FileInputStream(path)); f.read(buffer); ret = new String(buffer); } catch (IOException e) { throw new OopsException(e, "Error reading: " + path); } return ret; }
From source file:net.firejack.platform.core.utils.InstallUtils.java
/** * @param file/* w w w . ja va 2s . co m*/ * @return */ public static <E extends Entry> Environments<E> deserialize(File file) { try { return deserialize(new BufferedInputStream(new FileInputStream(file))); } catch (Exception e) { logger.warn("The environment.xml has not been found."); } return null; }
From source file:Main.java
public static void addEntryContent(ZipOutputStream zos, String entryFileName) throws IOException, FileNotFoundException { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(entryFileName)); byte[] buffer = new byte[1024]; int count = -1; while ((count = bis.read(buffer)) != -1) { zos.write(buffer, 0, count);//from www. j a va 2s .com } bis.close(); }