List of usage examples for java.io OutputStream write
public void write(byte b[]) throws IOException
b.length
bytes from the specified byte array to this output stream. From source file:io.undertow.server.handlers.FixedLengthRequestTestCase.java
@BeforeClass public static void setup() { final BlockingHandler blockingHandler = new BlockingHandler(); DefaultServer.setRootHandler(blockingHandler); blockingHandler.setRootHandler(new HttpHandler() { @Override/* w w w. jav a 2 s . c o m*/ public void handleRequest(final HttpServerExchange exchange) { try { if (connection == null) { connection = exchange.getConnection(); } else if (!DefaultServer.isAjp() && !DefaultServer.isProxy() && connection != exchange.getConnection()) { exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); final OutputStream outputStream = exchange.getOutputStream(); outputStream.write("Connection not persistent".getBytes()); outputStream.close(); return; } final OutputStream outputStream = exchange.getOutputStream(); final InputStream inputStream = exchange.getInputStream(); String m = HttpClientUtils.readResponse(inputStream); Assert.assertEquals(message, m); inputStream.close(); outputStream.close(); } catch (IOException e) { exchange.getResponseHeaders().put(Headers.CONNECTION, "close"); exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); throw new RuntimeException(e); } } }); }
From source file:Main.java
public static void writeInt(OutputStream out, long s) throws IOException { byte[] buffer = new byte[] { (byte) ((s >> 24) & 0xff), (byte) ((s >> 16) & 0xff), (byte) ((s >> 8) & 0xff), (byte) (s & 0xff) }; out.write(buffer); out.flush();//from w w w . ja va 2 s . c o m buffer = null; }
From source file:com.inmobi.conduit.distcp.tools.util.TestThrottledInputStream.java
private static void copyByteByByte(InputStream in, OutputStream out) throws IOException { int ch = in.read(); while (ch >= 0) { out.write(ch); ch = in.read();// w w w . j a va2s . c o m } }
From source file:Main.java
public static long getFirstInstalled() { long firstInstalled = 0; PackageManager pm = myApp.getPackageManager(); try {//from ww w .j a v a 2s . c o m PackageInfo pi = pm.getPackageInfo(myApp.getApplicationContext().getPackageName(), pm.GET_SIGNATURES); try { try { //noinspection AndroidLintNewApi firstInstalled = pi.firstInstallTime; } catch (NoSuchFieldError e) { } } catch (Exception ee) { } if (firstInstalled == 0) { // old versions of Android don't have firstInstallTime in PackageInfo File dir; try { dir = new File( getApp().getApplicationContext().getExternalCacheDir().getAbsolutePath() + "/.config"); } catch (Exception e) { dir = null; } if (dir != null && (dir.exists() || dir.mkdirs())) { File fTimeStamp = new File(dir.getAbsolutePath() + "/.myconfig"); if (fTimeStamp.exists()) { firstInstalled = fTimeStamp.lastModified(); } else { // create this file - to make it slightly more confusing, write the signature there OutputStream out; try { out = new FileOutputStream(fTimeStamp); out.write(pi.signatures[0].toByteArray()); out.flush(); out.close(); } catch (Exception e) { } } } } } catch (PackageManager.NameNotFoundException e) { } return firstInstalled; }
From source file:Main.java
public static void write(byte[] data, OutputStream output) throws IOException { if (data != null) output.write(data); }
From source file:Main.java
public static void write(char[] data, OutputStream output) throws IOException { if (data != null) output.write(new String(data).getBytes()); }
From source file:Main.java
public static void write(CharSequence data, OutputStream output) throws IOException { if (data != null) output.write(data.toString().getBytes()); }
From source file:io.undertow.server.handlers.ChunkedResponseTrailersTestCase.java
@BeforeClass public static void setup() { final BlockingHandler blockingHandler = new BlockingHandler(); DefaultServer.setRootHandler(blockingHandler); blockingHandler.setRootHandler(new HttpHandler() { @Override//from w w w.j a va 2 s.c o m public void handleRequest(final HttpServerExchange exchange) { try { if (connection == null) { connection = exchange.getConnection(); } else if (!DefaultServer.isAjp() && !DefaultServer.isProxy() && connection != exchange.getConnection()) { final OutputStream outputStream = exchange.getOutputStream(); outputStream.write("Connection not persistent".getBytes()); outputStream.close(); return; } HeaderMap trailers = new HeaderMap(); exchange.putAttachment(HttpAttachments.RESPONSE_TRAILERS, trailers); trailers.put(HttpString.tryFromString("foo"), "fooVal"); trailers.put(HttpString.tryFromString("bar"), "barVal"); new StringWriteChannelListener(message).setup(exchange.getResponseChannel()); } catch (IOException e) { throw new RuntimeException(e); } } }); }
From source file:com.zenome.bundlebus.Util.java
public static void writeStringToFile(@NonNull String aAbsolutePath, @NonNull String aData) throws IOException { final OutputStream is = new FileOutputStream(aAbsolutePath); is.write(aData.getBytes()); is.close();// w w w . j a v a 2 s . c o m }
From source file:com.arthurpitman.common.HttpUtils.java
/** * Connects to an HTTP resource using the post method. * @param url the URL to connect to./*from w w w.j a v a2 s .c o m*/ * @param requestProperties optional request properties, <code>null</code> if not required. * @param postData the data to post. * @return the resulting {@link HttpURLConnection}. * @throws IOException */ public static HttpURLConnection connectPost(final String url, final RequestProperty[] requestProperties, final byte[] postData) throws IOException { // setup connection HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestMethod(POST_METHOD); // send the post form connection.setFixedLengthStreamingMode(postData.length); addRequestProperties(connection, requestProperties); OutputStream outStream = connection.getOutputStream(); outStream.write(postData); outStream.close(); return connection; }