List of usage examples for java.io BufferedInputStream BufferedInputStream
public BufferedInputStream(InputStream in, int size)
BufferedInputStream
with the specified buffer size, and saves its argument, the input stream in
, for later use. From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("C:/test.txt"); // input stream is converted to buffered input stream BufferedInputStream bis = new BufferedInputStream(is, 200); }
From source file:hd3gtv.tools.Hexview.java
public static void main(String[] args) throws IOException { if (args.length == 0) { System.err.println("Usage file1.ext file2.ext ..."); System.exit(1);//from w w w.jav a2 s. c o m } Arrays.asList(args).forEach(f -> { try { File file = new File(f); InputStream in = new BufferedInputStream(new FileInputStream(file), 0xFFFF); byte[] buffer = new byte[COLS * ROWS]; int len; Hexview hv = null; while ((len = in.read(buffer)) != -1) { if (hv == null) { hv = new Hexview(buffer, 0, len); hv.setSize(file.length()); } else { hv.update(buffer, 0, len); } System.out.println(hv.getView()); } IOUtils.closeQuietly(in); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }); }
From source file:glacierpipe.GlacierPipeMain.java
public static void main(String[] args) throws IOException, ParseException { CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(OPTIONS, args); if (cmd.hasOption("help")) { try (PrintWriter writer = new PrintWriter(System.err)) { printHelp(writer);// ww w .j a va 2 s . c om } System.exit(0); } else if (cmd.hasOption("upload")) { // Turn the CommandLine into Properties Properties cliProperties = new Properties(); for (Iterator<?> i = cmd.iterator(); i.hasNext();) { Option o = (Option) i.next(); String opt = o.getLongOpt(); opt = opt != null ? opt : o.getOpt(); String value = o.getValue(); value = value != null ? value : ""; cliProperties.setProperty(opt, value); } // Build up a configuration ConfigBuilder configBuilder = new ConfigBuilder(); // Archive name List<?> archiveList = cmd.getArgList(); if (archiveList.size() > 1) { throw new ParseException("Too many arguments"); } else if (archiveList.isEmpty()) { throw new ParseException("No archive name provided"); } configBuilder.setArchive(archiveList.get(0).toString()); // All other arguments on the command line configBuilder.setFromProperties(cliProperties); // Load any config from the properties file Properties fileProperties = new Properties(); try (InputStream in = new FileInputStream(configBuilder.propertiesFile)) { fileProperties.load(in); } catch (IOException e) { System.err.printf("Warning: unable to read properties file %s; %s%n", configBuilder.propertiesFile, e); } configBuilder.setFromProperties(fileProperties); // ... Config config = new Config(configBuilder); IOBuffer buffer = new MemoryIOBuffer(config.partSize); AmazonGlacierClient client = new AmazonGlacierClient( new BasicAWSCredentials(config.accessKey, config.secretKey)); client.setEndpoint(config.endpoint); // Actual upload try (InputStream in = new BufferedInputStream(System.in, 4096); PrintWriter writer = new PrintWriter(System.err); ObservableProperties configMonitor = config.reloadProperties ? new ObservableProperties(config.propertiesFile) : null; ProxyingThrottlingStrategy throttlingStrategy = new ProxyingThrottlingStrategy(config);) { TerminalGlacierPipeObserver observer = new TerminalGlacierPipeObserver(writer); if (configMonitor != null) { configMonitor.registerObserver(throttlingStrategy); } GlacierPipe pipe = new GlacierPipe(buffer, observer, config.maxRetries, throttlingStrategy); pipe.pipe(client, config.vault, config.archive, in); } catch (Exception e) { e.printStackTrace(System.err); } System.exit(0); } else { try (PrintWriter writer = new PrintWriter(System.err)) { writer.println("No action specified."); printHelp(writer); } System.exit(-1); } }
From source file:com.netflix.aegisthus.tools.SSTableExport.java
@SuppressWarnings("rawtypes") public static void main(String[] args) throws IOException { String usage = String.format("Usage: %s <sstable>", SSTableExport.class.getName()); CommandLineParser parser = new PosixParser(); try {//from ww w. ja va2 s . c o m cmd = parser.parse(options, args); } catch (ParseException e1) { System.err.println(e1.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } if (cmd.getArgs().length != 1) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } Map<String, AbstractType> convertors = null; if (cmd.hasOption(COLUMN_NAME_TYPE)) { try { convertors = new HashMap<String, AbstractType>(); convertors.put(SSTableScanner.COLUMN_NAME_KEY, TypeParser.parse(cmd.getOptionValue(COLUMN_NAME_TYPE))); } catch (ConfigurationException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } catch (SyntaxException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } } Descriptor.Version version = null; if (cmd.hasOption(OPT_VERSION)) { version = new Descriptor.Version(cmd.getOptionValue(OPT_VERSION)); } if (cmd.hasOption(INDEX_SPLIT)) { String ssTableFileName; DataInput input = null; if ("-".equals(cmd.getArgs()[0])) { ssTableFileName = System.getProperty("aegisthus.file.name"); input = new DataInputStream(new BufferedInputStream(System.in, 65536 * 10)); } else { ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath(); input = new DataInputStream( new BufferedInputStream(new FileInputStream(ssTableFileName), 65536 * 10)); } exportIndexSplit(ssTableFileName, input); } else if (cmd.hasOption(INDEX)) { String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath(); exportIndex(ssTableFileName); } else if (cmd.hasOption(ROWSIZE)) { String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath(); exportRowSize(ssTableFileName); } else if ("-".equals(cmd.getArgs()[0])) { if (version == null) { System.err.println("when streaming must supply file version"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } exportStream(version); } else { String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath(); FileInputStream fis = new FileInputStream(ssTableFileName); InputStream inputStream = new DataInputStream(new BufferedInputStream(fis, 65536 * 10)); long end = -1; if (cmd.hasOption(END)) { end = Long.valueOf(cmd.getOptionValue(END)); } if (cmd.hasOption(OPT_COMP)) { CompressionMetadata cm = new CompressionMetadata( new BufferedInputStream(new FileInputStream(cmd.getOptionValue(OPT_COMP)), 65536), fis.getChannel().size()); inputStream = new CompressionInputStream(inputStream, cm); end = cm.getDataLength(); } DataInputStream input = new DataInputStream(inputStream); if (version == null) { version = Descriptor.fromFilename(ssTableFileName).version; } SSTableScanner scanner = new SSTableScanner(input, convertors, end, version); if (cmd.hasOption(OPT_MAX_COLUMN_SIZE)) { scanner.setMaxColSize(Long.parseLong(cmd.getOptionValue(OPT_MAX_COLUMN_SIZE))); } export(scanner); if (cmd.hasOption(OPT_MAX_COLUMN_SIZE)) { if (scanner.getErrorRowCount() > 0) { System.err.println(String.format("%d rows were too large", scanner.getErrorRowCount())); } } } }
From source file:Main.java
public static InputStream U7openStream(String nm) throws IOException { String fname = getSystemPath(nm); return new BufferedInputStream(new FileInputStream(fname), 0x8000); }
From source file:Main.java
public static String toString(InputStream in) throws IOException { if (in == null) { return null; }//w ww . j av a2 s . c om BufferedReader br = new BufferedReader(new InputStreamReader(new BufferedInputStream(in, 8 * 1024))); StringBuilder result = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { result.append(line); } return result.toString(); }
From source file:Main.java
public static boolean WriteFileFromUrl(String url, String filename) { try {/*from w w w. j ava2 s . com*/ URL fileUrl = new URL(url); URLConnection connection = fileUrl.openConnection(); InputStream inputStream = new BufferedInputStream(fileUrl.openStream(), 10240); File cacheFile = new File(filename); FileOutputStream outputStream = new FileOutputStream(cacheFile); byte buffer[] = new byte[1024]; int dataSize; int loadedSize = 0; while ((dataSize = inputStream.read(buffer)) != -1) { loadedSize += dataSize; outputStream.write(buffer, 0, dataSize); } outputStream.close(); return true; } catch (Exception e) { Log.d("#StorageHelper Error:", e.toString()); return false; } }
From source file:Main.java
public static InputStream U7openStream2(String nm1, String nm2) { String nm = U7exists(nm1);//from w ww . j a v a 2 s .c o m if (nm != null) try { return new BufferedInputStream(new FileInputStream(nm), 0x8000); } catch (IOException e) { } nm = U7exists(nm2); if (nm != null) try { return new BufferedInputStream(new FileInputStream(nm), 0x8000); } catch (IOException e) { } return null; }
From source file:Main.java
public static Bitmap loadImageFromUrl(String url) { ByteArrayOutputStream out = null; Bitmap bitmap = null;// w ww. j a v a 2 s . c o m int BUFFER_SIZE = 1024 * 8; try { BufferedInputStream in = new BufferedInputStream(new URL(url).openStream(), BUFFER_SIZE); out = new ByteArrayOutputStream(BUFFER_SIZE); int length = 0; byte[] tem = new byte[BUFFER_SIZE]; length = in.read(tem); while (length != -1) { out.write(tem, 0, length); out.flush(); length = in.read(tem); } in.close(); if (out.toByteArray().length != 0) { bitmap = BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()); } else { out.close(); return null; } out.close(); } catch (OutOfMemoryError e) { out.reset(); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = 2; opts.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size(), opts); return bitmap; } catch (Exception e) { return bitmap; } return bitmap; }
From source file:Main.java
public static Bitmap GetLocalOrNetBitmap(String url) { Bitmap bitmap = null;/*from w w w .j a v a 2 s . co m*/ InputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new URL(url).openStream(), 1024); final ByteArrayOutputStream dataStream = new ByteArrayOutputStream(); out = new BufferedOutputStream(dataStream, 1024); copy(in, out); out.flush(); byte[] data = dataStream.toByteArray(); bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); data = null; return bitmap; } catch (IOException e) { e.printStackTrace(); return null; } }