List of usage examples for java.io OutputStream write
public void write(byte b[], int off, int len) throws IOException
len
bytes from the specified byte array starting at offset off
to this output stream. From source file:Main.java
public static void main(String[] args) throws IOException { ServerSocket servsock = new ServerSocket(123456); File myFile = new File("s.pdf"); while (true) {//from w w w. ja v a2 s .c o m Socket sock = servsock.accept(); byte[] mybytearray = new byte[(int) myFile.length()]; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile)); bis.read(mybytearray, 0, mybytearray.length); OutputStream os = sock.getOutputStream(); os.write(mybytearray, 0, mybytearray.length); os.flush(); sock.close(); } }
From source file:Main.java
public static void main(String[] args) { byte[] b = { 'h', 'e', 'l', 'l', 'o' }; try {//from ww w. ja va 2s. co m OutputStream os = new FileOutputStream("test.txt"); InputStream is = new FileInputStream("test.txt"); os.write(b, 0, 3); for (int i = 0; i < 3; i++) { System.out.print((char) is.read()); } os.close(); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { ZipInputStream in = new ZipInputStream(new FileInputStream("source.zip")); OutputStream out = new FileOutputStream("target"); byte[] buf = new byte[1024]; int len;/*from w w w . j a v a 2s . c o m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); in.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String source = "s.gzip"; GZIPInputStream in = new GZIPInputStream(new FileInputStream(source)); String target = "outfile"; OutputStream out = new FileOutputStream(target); byte[] buf = new byte[1024]; int len;//from w ww.j a v a 2 s . c o m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String inFilename = "infile.zip"; ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename)); ZipEntry entry = in.getNextEntry(); String outFilename = "o"; OutputStream out = new FileOutputStream(outFilename); byte[] buf = new byte[1024]; int len;/* w w w . j a v a2 s .c om*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Socket socket = new Socket("localhost", 8000); File file = new File("C:/Users/abc/Desktop/image.jpg"); FileInputStream fileInputStream = new FileInputStream(file); byte[] fileBytes = new byte[(int) file.length()]; OutputStream outputStream = socket.getOutputStream(); int content;//from ww w. j av a2 s . c o m while ((content = fileInputStream.read(fileBytes)) != -1) { outputStream.write(fileBytes, 0, (int) file.length()); } System.out.println("file size is " + fileBytes.length); for (byte a : fileBytes) { System.out.println(a); } socket.close(); fileInputStream.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String inFilename = "infile.gzip"; GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename)); String outFilename = "outfile"; OutputStream out = new FileOutputStream(outFilename); byte[] buf = new byte[1024]; int len;//from www . j a v a 2 s . c o m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:com.rest.samples.getImage.java
public static void main(String[] args) { // TODO code application logic here String url = "https://api.adorable.io/avatars/eyes1"; try {/* www . j a va 2 s.com*/ HttpClient hc = HttpClientBuilder.create().build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/png"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); OutputStream os = new FileOutputStream(new File("img.png")); int read = 0; byte[] bytes = new byte[2048]; while ((read = is.read(bytes)) != -1) { os.write(bytes, 0, read); } is.close(); os.close(); } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.rest.samples.getReportFromJasperServer.java
public static void main(String[] args) { // TODO code application logic here String url = "http://username:password@10.49.28.3:8081/jasperserver/rest_v2/reports/Reportes/vencimientos.pdf?feini=2016-09-30&fefin=2016-09-30"; try {//from w ww .j av a 2s. c o m HttpClient hc = HttpClientBuilder.create().build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/pdf"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); OutputStream os = new FileOutputStream(new File("vencimientos.pdf")); int read = 0; byte[] bytes = new byte[2048]; while ((read = is.read(bytes)) != -1) { os.write(bytes, 0, read); } is.close(); os.close(); if (Desktop.isDesktopSupported()) { File pdfFile = new File("vencimientos.pdf"); Desktop.getDesktop().open(pdfFile); } } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipInputStream inStream = new ZipInputStream(new FileInputStream("compressed.zip")); OutputStream outStream = new FileOutputStream("extracted.txt"); byte[] buffer = new byte[1024]; int read;/* w ww. j a v a 2s. c o m*/ ZipEntry entry; if ((entry = inStream.getNextEntry()) != null) { while ((read = inStream.read(buffer)) > 0) { outStream.write(buffer, 0, read); } } outStream.close(); inStream.close(); }