List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { int i;/* w w w .jav a2s .c o m*/ InputStream is = new FileInputStream("C://test.txt"); while ((i = is.read()) != -1) { // converts int to char char c = (char) i; System.out.println("Character Read: " + c); // skip one byte is.skip(1); } is.close(); }
From source file:com.glaf.jbpm.config.JbpmExtensionWriter.java
public static void main(String[] args) throws Exception { java.io.InputStream inputStream = new java.io.FileInputStream(args[0]); JbpmExtensionReader reader = new JbpmExtensionReader(); List<Extension> extensions = reader.readTasks(inputStream); inputStream.close(); inputStream = null;//from w ww .ja va 2 s .c om JbpmExtensionWriter writer = new JbpmExtensionWriter(); Document doc = writer.write(extensions); byte[] bytes = Dom4jUtils.getBytesFromPrettyDocument(doc, "GBK"); System.out.println(new String(bytes)); }
From source file:com.tc.simple.apn.quicktests.Test.java
/** * @param args/*from w ww . j ava 2 s. c om*/ */ public static void main(String[] args) { SSLSocket socket = null; try { String host = "gateway.sandbox.push.apple.com"; int port = 2195; String token = "de7f197546e41a76684f8e2d89f397ed165298d7772f4bd9b0f39c674b185b0f"; System.out.println(token.toCharArray().length); //String token = "8cebc7c08f79fa62f0994eb4298387ff930857ff8d14a50de431559cf476b223"; KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(Test.class.getResourceAsStream("egram-dev-apn.p12"), "xxxxxxxxx".toCharArray()); KeyManagerFactory keyMgrFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyMgrFactory.init(keyStore, "xxxxxxxxx".toCharArray()); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(keyMgrFactory.getKeyManagers(), null, null); SSLSocketFactory socketFactory = sslContext.getSocketFactory(); socket = (SSLSocket) socketFactory.createSocket(host, port); String[] cipherSuites = socket.getSupportedCipherSuites(); socket.setEnabledCipherSuites(cipherSuites); socket.startHandshake(); char[] t = token.toCharArray(); byte[] b = Hex.decodeHex(t); OutputStream outputstream = socket.getOutputStream(); String payload = "{\"aps\":{\"alert\":\"yabadabadooo\"}}"; int expiry = (int) ((System.currentTimeMillis() / 1000L) + 7200); ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bout); //command dos.writeByte(1); //id dos.writeInt(900); //expiry dos.writeInt(expiry); //token length. dos.writeShort(b.length); //token dos.write(b); //payload length dos.writeShort(payload.length()); //payload. dos.write(payload.getBytes()); byte[] byteMe = bout.toByteArray(); socket.getOutputStream().write(byteMe); socket.setSoTimeout(900); InputStream in = socket.getInputStream(); System.out.println(APNErrors.getError(in.read())); in.close(); outputstream.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.cloudera.earthquake.GetData.java
public static void main(String[] args) throws IOException { URL url = new URL("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect();/* ww w .ja va 2s .c o m*/ InputStream connStream = conn.getInputStream(); FileSystem hdfs = FileSystem.get(new Configuration()); FSDataOutputStream outStream = hdfs.create(new Path(args[0], "month.txt")); IOUtils.copy(connStream, outStream); outStream.close(); connStream.close(); conn.disconnect(); }
From source file:Main.java
public static void main(String[] arg) throws Throwable { File f = new File(arg[0]); InputStream in = new FileInputStream(f); byte[] buff = new byte[8000]; int bytesRead = 0; ByteArrayOutputStream bao = new ByteArrayOutputStream(); while ((bytesRead = in.read(buff)) != -1) { bao.write(buff, 0, bytesRead);/*from w w w .j a v a 2 s . c om*/ } in.close(); byte[] data = bao.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(data); System.out.println(bin.available()); }
From source file:Main.java
public static void main(String[] args) throws IOException { URL url = new URL("http://www.java2s.com/style/download.png"); InputStream inputStream = url.openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int n = 0;/*from www .j a va2 s. c o m*/ while (-1 != (n = inputStream.read(buffer))) { output.write(buffer, 0, n); } inputStream.close(); byte[] data = output.toByteArray(); OutputStream out = new FileOutputStream("data.png"); out.write(data); out.close(); for (byte b : data) { System.out.printf("0x%x ", b); } }
From source file:com.asakusafw.generator.HadoopBulkLoaderDDLGenerator.java
/** * HadoopBulkLoader?????//www. j a v a 2 s . com * * @param args * ?? * @throws Exception * ?????? */ public static void main(String[] args) throws Exception { String outputTablesString = findVariable(ENV_BULKLOADER_TABLES, true); List<String> outputTableList = null; if (outputTablesString != null && !OUTPUT_TABLES_PROPERTY.equals(outputTablesString)) { String[] outputTables = outputTablesString.trim().split("\\s+"); outputTableList = Arrays.asList(outputTables); } String ddlTemplate; InputStream in = HadoopBulkLoaderDDLGenerator.class.getResourceAsStream(TEMPLATE_DDL_FILENAME); try { ddlTemplate = IOUtils.toString(in); } finally { in.close(); } StringBuilder sb = new StringBuilder(); for (String tableName : args) { if (outputTableList == null || outputTableList.contains(tableName)) { String tableddl = ddlTemplate.replaceAll(TABLENAME_REPLACE_STRING, tableName); sb.append(tableddl); } } String outputFilePath = findVariable(ENV_BULKLOADER_GENDDL, true); if (outputFilePath == null) { throw new RuntimeException( "ASAKUSA_BULKLOADER_TABLES???????"); } FileUtils.write(new File(outputFilePath), sb); }
From source file:com.eucalyptus.auth.policy.PolicyParserTest.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Requires input policy file"); System.exit(1);/*w w w .ja v a2 s.c om*/ } InputStream input = new FileInputStream(args[0]); String policy = readInputAsString(input); PolicyEntity parsed = PolicyParser.getInstance().parse(policy); printPolicy(parsed); input.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int i = 0;// ww w .ja va 2 s. c o m // new input stream created InputStream is = new FileInputStream("C://test.txt"); // read till the end of the stream while ((i = is.read()) != -1) { // convert integer to character char c = (char) i; // print System.out.println("Character Read: " + c); } is.close(); }
From source file:Main.java
public static void main(String[] args) { byte[] b = { 'h', 'e', 'l', 'l', 'o' }; try {/*w ww. ja v a 2s.c o m*/ // create a new output stream OutputStream os = new FileOutputStream("test.txt"); // craete a new input stream InputStream is = new FileInputStream("test.txt"); // write something os.write(b); // read what we wrote for (int i = 0; i < b.length; i++) { System.out.print((char) is.read()); } os.close(); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }