/** * Gets an input stream for the corresponding file. * * @param file The file to create the input stream from. * @return InputStream */ protected InputStream getInputStream(File file) throws IOException, FileNotFoundException { BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file)); return reader; }
public ByteStreamGobbler(String name, InputStream is, OutputStream out) { super(name); this.inStream = new BufferedInputStream(is); this.outStream = new BufferedOutputStream(out); }
public static void bsdiff(File oldFile, File newFile, File diffFile) throws IOException { InputStream oldInputStream = new BufferedInputStream(new FileInputStream(oldFile)); InputStream newInputStream = new BufferedInputStream(new FileInputStream(newFile)); OutputStream diffOutputStream = new FileOutputStream(diffFile); try { byte[] diffBytes = bsdiff(oldInputStream, (int) oldFile.length(), newInputStream, (int) newFile.length()); diffOutputStream.write(diffBytes); } finally { diffOutputStream.close(); } }
public void chop() { File targetFile = new File(txnLogFile.getParentFile(), txnLogFile.getName() + ".chopped" + zxid); try ( InputStream is = new BufferedInputStream(new FileInputStream(txnLogFile)); OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile)) ) { if (!LogChopper.chop(is, os, zxid)) { throw new TxnLogToolkitException(ExitCode.INVALID_INVOCATION.getValue(), "Failed to chop %s", txnLogFile.getName()); } } catch (Exception e) { System.out.println("Got exception: " + e.getMessage()); } }
@Override public InputStream openStream(String resourceName) throws IOException { File file = new File(dirName, resourceName); if (!file.exists()) { return null; } return new BufferedInputStream(new FileInputStream(file)); }
public SetupPreferences () { if (!file.exists()) return; InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); properties.loadFromXML(in); } catch (Throwable t) { t.printStackTrace(); } finally { if (in != null) try { in.close(); } catch (IOException e) { } } }
public ProgressByteEntity(File file) { super(); mLength = file.length(); try { mInputStream = new BufferedInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
public static void gunzip(File source, File dest, boolean deleteSource) throws IOException { byte[] buffer = new byte[2^20]; FileOutputStream out = new FileOutputStream(dest); GZIPInputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(source))); int l; while ((l = in.read(buffer)) > 0) out.write(buffer, 0, l); in.close(); out.close(); if (deleteSource && dest.exists()) source.delete(); }
public void open(String fileName) throws IOException { File file = new File(fileName); size = (int) file.length() / UNIT_SIZE; check = new int[size]; base = new int[size]; DataInputStream is = null; try { is = new DataInputStream(new BufferedInputStream( IOUtil.newInputStream(fileName), BUF_SIZE)); for (int i = 0; i < size; i++) { base[i] = is.readInt(); check[i] = is.readInt(); } } finally { if (is != null) is.close(); } }
InputStream input = new BufferedInputStream(connection.getInputStream()); OutputStream output = new FileOutputStream("/sdcard/BarcodeScanner-debug.apk"); input.close(); } catch (IOException e) { e.printStackTrace();
static public void copyToStream(File src, OutputStream os) throws IOException { final InputStream fis = new BufferedInputStream(new FileInputStream(src)); final OutputStream fos = new BufferedOutputStream(os); copyInternal(fis, fos); }
private void copyImageToMemory(File outFile) { try { BufferedOutputStream os = new BufferedOutputStream( new FileOutputStream(outFile)); BufferedInputStream is = new BufferedInputStream(getResources() .openRawResource(R.raw.painter)); copy(is, os); } catch (FileNotFoundException e) { Log.e(TAG, "FileNotFoundException"); } }
URL url = new URL("http://www.yahoo.com/image_to_read.jpg"); InputStream in = new BufferedInputStream(url.openStream()); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int n = 0; while (-1!=(n=in.read(buf))) { out.write(buf, 0, n); } out.close(); in.close(); byte[] response = out.toByteArray();
final void process(Socket clnt) throws IOException { InputStream in = new BufferedInputStream(clnt.getInputStream()); String cmd = readLine(in); logging(clnt.getInetAddress().getHostName(), new Date().toString(), cmd); while (skipLine(in) > 0){ } OutputStream out = new BufferedOutputStream(clnt.getOutputStream()); try { doReply(in, out, cmd); } catch (BadHttpRequest e) { replyError(out, e); } out.flush(); in.close(); out.close(); clnt.close(); }
BufferedInputStream bis = new BufferedInputStream(entity.getContent()); String filePath = "sample.txt"; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath))); int inByte; while((inByte = bis.read()) != -1) bos.write(inByte); bis.close(); bos.close();
public void open(String fileName) throws IOException { File file = new File(fileName); size = (int) file.length() / UNIT_SIZE; check = new int[size]; base = new int[size]; DataInputStream is = null; try { is = new DataInputStream(new BufferedInputStream( new FileInputStream(file), BUF_SIZE)); for (int i = 0; i < size; i++) { base[i] = is.readInt(); check[i] = is.readInt(); } } finally { if (is != null) is.close(); } }
private static DependencyGraph loadGraph(String filename) throws Exception { File file = new File(filename); if (!file.exists()) { System.err.println("unable to find " + filename); ExitCode.DEPENDENCY_GRAPH_FAILURE.doSystemExit(); } ObjectInputStream ois = new DDObjectInputStream(new BufferedInputStream(new FileInputStream(file))); DependencyGraph graph = (DependencyGraph) ois.readObject(); return graph; }
public static int countLines(String filename) throws IOException { InputStream is = new BufferedInputStream(new FileInputStream(filename)); try { byte[] c = new byte[1024]; int count = 0; int readChars = 0; boolean empty = true; while ((readChars = is.read(c)) != -1) { empty = false; for (int i = 0; i < readChars; ++i) { if (c[i] == '\n') { ++count; } } } return (count == 0 && !empty) ? 1 : count; } finally { is.close(); } }
public static String readFileAsString(String filePath) { byte[] buffer = new byte[(int) getFile(filePath).length()]; BufferedInputStream inputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(getFile(filePath))); inputStream.read(buffer); } catch (Exception e) { throw new ActivitiException("Couldn't read file " + filePath + ": " + e.getMessage()); } finally { IoUtil.closeSilently(inputStream); } return new String(buffer); }
@Override public InputStream _newInputStream() throws FileNotFoundException { return new BufferedInputStream(new FileInputStream(file)); } }