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:MainClass.java
public static void main(String[] args) throws Exception { String serverName = System.getProperty("WHOIS_SERVER", DEFAULT_HOST); InetAddress server = null;//from ww w . ja v a 2 s . c om server = InetAddress.getByName(serverName); Socket theSocket = new Socket(server, DEFAULT_PORT); Writer out = new OutputStreamWriter(theSocket.getOutputStream(), "8859_1"); out.write("\r\n"); out.flush(); InputStream raw = theSocket.getInputStream(); InputStream in = new BufferedInputStream(theSocket.getInputStream()); int c; while ((c = in.read()) != -1) System.out.write(c); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { URL u = new URL("http://www.java2s.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 header = uc.getHeaderField(j); String key = uc.getHeaderFieldKey(j); if (header == null || key == null) break; System.out.println(uc.getHeaderFieldKey(j) + ": " + header); }/*w ww .j a v a 2 s .c o m*/ InputStream in = new BufferedInputStream(uc.getInputStream()); Reader r = new InputStreamReader(in); int c; while ((c = r.read()) != -1) { System.out.print((char) c); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); final DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); if (job instanceof CancelablePrintJob) { CancelablePrintJob cancelJob = (CancelablePrintJob) job; try {// w w w.ja va 2s . co m cancelJob.cancel(); } catch (PrintException e) { } } job.print(doc, null); pjDone.waitForDone(); is.close(); }
From source file:Main.java
public static void main(String[] args) { int[] x = new int[] { 1, 2, 3 }; int[] y = new int[] { 4, 5, 6 }; Polygon polygon = new Polygon(x, y, x.length); try {/*w w w. j a v a2 s. co m*/ ObjectOutputStream objectOut = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("Polygons.bin"))); objectOut.writeObject(polygon); objectOut.close(); } catch (IOException e) { e.printStackTrace(System.err); } try { ObjectInputStream objectIn = new ObjectInputStream( new BufferedInputStream(new FileInputStream("Polygons.bin"))); Polygon theLine = (Polygon) objectIn.readObject(); System.out.println(theLine); objectIn.close(); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { try {/*from www.j a va2s . c o m*/ OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory .lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); final DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); if (job instanceof CancelablePrintJob) { CancelablePrintJob cancelJob = (CancelablePrintJob) job; try { cancelJob.cancel(); } catch (PrintException e) { } } job.print(doc, null); pjDone.waitForDone(); is.close(); } catch (PrintException e) { if (e.getCause() instanceof PrinterAbortException) { System.out.println("Print job was cancelled"); } } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Junk obj1 = new Junk("A"); Junk obj2 = new Junk("B"); Junk obj3 = new Junk("V"); ObjectOutputStream objectOut = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("C:/JunkObjects.bin"))); objectOut.writeObject(obj1); // Write object objectOut.writeObject(obj2); // Write object objectOut.writeObject(obj3); // Write object objectOut.close(); // Close the output stream ObjectInputStream objectIn = null; int objectCount = 0; Junk object = null;//from w w w . j a v a 2s. c om objectIn = new ObjectInputStream(new BufferedInputStream(new FileInputStream("C:/JunkObjects.bin"))); // Read from the stream until we hit the end while (objectCount < 3) { object = (Junk) objectIn.readObject(); objectCount++; System.out.println(object); } objectIn.close(); }
From source file:com.ning.metrics.collector.util.LocalFileReader.java
public static void main(String[] args) throws IOException { InputStream stream = null;//from w w w . jav a 2 s . co m try { stream = new BufferedInputStream(new FileInputStream(args[0])); final SmileEnvelopeEventDeserializer deserializer = new SmileEnvelopeEventDeserializer(stream, false); while (deserializer.hasNextEvent()) { final SmileEnvelopeEvent event = deserializer.getNextEvent(); final JsonNode node = (JsonNode) event.getData(); final Iterator<JsonNode> elements = node.elements(); boolean first = true; while (elements.hasNext()) { final JsonNode jsonNode = elements.next(); if (!first) { System.out.print(","); } System.out.print(jsonNode.toString()); first = false; } System.out.print("\n"); } } finally { if (stream != null) { stream.close(); } System.out.flush(); } }
From source file:com.threerings.getdown.tools.AppletParamSigner.java
public static void main(String[] args) { try {//from ww w . j a v a 2s . c om if (args.length != 7) { System.err .println("AppletParamSigner keystore storepass alias keypass " + "appbase appname imgpath"); System.exit(255); } String keystore = args[0]; String storepass = args[1]; String alias = args[2]; String keypass = args[3]; String appbase = args[4]; String appname = args[5]; String imgpath = args[6]; String params = appbase + appname + imgpath; KeyStore store = KeyStore.getInstance("JKS"); store.load(new BufferedInputStream(new FileInputStream(keystore)), storepass.toCharArray()); PrivateKey key = (PrivateKey) store.getKey(alias, keypass.toCharArray()); Signature sig = Signature.getInstance("SHA1withRSA"); sig.initSign(key); sig.update(params.getBytes()); String signed = new String(Base64.encodeBase64(sig.sign())); System.out.println("<param name=\"appbase\" value=\"" + appbase + "\" />"); System.out.println("<param name=\"appname\" value=\"" + appname + "\" />"); System.out.println("<param name=\"bgimage\" value=\"" + imgpath + "\" />"); System.out.println("<param name=\"signature\" value=\"" + signed + "\" />"); } catch (Exception e) { System.err.println("Failed to produce signature."); e.printStackTrace(); } }
From source file:com.jeffy.hdfs.HDFSWriteFile.java
/** * ??hdfs// www .j a v a 2 s .com * * @param args */ public static void main(String[] args) { if (args.length < 2) { System.err.println("Please input two parameter!"); System.out.println("Parameter: localfile hdfsfile"); System.exit(1); } String localPath = args[0]; String hdfsPath = args[1]; //?? Configuration config = new Configuration(); //?? try (InputStream in = new BufferedInputStream(new FileInputStream(localPath))) { FileSystem fs = FileSystem.get(URI.create(hdfsPath), config); try (FSDataOutputStream out = fs.create(new Path(hdfsPath), new Progressable() { @Override public void progress() { System.out.println("."); } })) { //??OutputStream,Hadooporg.apache.commons.io.IOUtils IOUtils.copy(in, out); System.out.println("File copy finished."); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:MyTest.DownloadFileTest.java
public static void main(String args[]) { CloseableHttpClient httpclient = HttpClients.createDefault(); String url = "http://www.myexperiment.org/workflows/16/download/Pathways_and_Gene_annotations_for_QTL_region-v7.t2flow?version=7"; System.out.println(url.charAt(50)); HttpGet httpget = new HttpGet(url); HttpEntity entity = null;/*from ww w. j av a 2s.c o m*/ try { HttpResponse response = httpclient.execute(httpget); entity = response.getEntity(); if (entity != null) { InputStream is = entity.getContent(); String filename = "testdata/Pathways_and_Gene_annotations_for_QTL_region-v7.t2flow"; BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filename))); int readedByte; while ((readedByte = bis.read()) != -1) { bos.write(readedByte); } bis.close(); bos.close(); } httpclient.close(); } catch (IOException ex) { Logger.getLogger(DownloadFileTest.class.getName()).log(Level.SEVERE, null, ex); } }