List of usage examples for java.io DataOutputStream write
public synchronized void write(int b) throws IOException
b
) to the underlying output stream. From source file:net.technicpack.launchercore.auth.AuthenticationService.java
private static String postJson(String url, String data) throws IOException { byte[] rawData = data.getBytes("UTF-8"); HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setUseCaches(false);// ww w . j a va2 s. c o m connection.setDoOutput(true); connection.setDoInput(true); connection.setConnectTimeout(15000); connection.setReadTimeout(15000); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); connection.setRequestProperty("Content-Length", rawData.length + ""); connection.setRequestProperty("Content-Language", "en-US"); DataOutputStream writer = new DataOutputStream(connection.getOutputStream()); writer.write(rawData); writer.flush(); writer.close(); InputStream stream = null; String returnable = null; try { stream = connection.getInputStream(); returnable = IOUtils.toString(stream); } catch (IOException e) { stream = connection.getErrorStream(); if (stream == null) { throw e; } } finally { try { if (stream != null) stream.close(); } catch (IOException e) { } } return returnable; }
From source file:com.eTilbudsavis.etasdk.network.impl.HttpURLNetwork.java
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request) throws IOException { byte[] body = request.getBody(); if (body != null) { connection.setDoOutput(true);/*from w w w. j ava2s. com*/ connection.addRequestProperty(HeaderUtils.CONTENT_TYPE, request.getBodyContentType()); DataOutputStream out = new DataOutputStream(connection.getOutputStream()); out.write(body); out.close(); } }
From source file:com.ning.arecibo.util.timeline.times.TimesAndSamplesCoder.java
public static byte[] combineTimesAndSamples(final byte[] times, final byte[] samples) { final int totalSamplesSize = 4 + times.length + samples.length; final ByteArrayOutputStream baStream = new ByteArrayOutputStream(totalSamplesSize); final DataOutputStream outputStream = new DataOutputStream(baStream); try {//www . ja va2 s . co m outputStream.writeInt(times.length); outputStream.write(times); outputStream.write(samples); outputStream.flush(); return baStream.toByteArray(); } catch (IOException e) { throw new IllegalStateException(String.format( "Exception reading timeByteCount in TimelineChunkMapper.map() for times %s, samples %s", Hex.encodeHex(times), Hex.encodeHex(samples)), e); } }
From source file:org.jcodec.samples.mux.AVCMP4Mux.java
private static Buffer formPacket(NALUnit nu, InputStream nextNALUnit) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); byte[] data = IOUtils.toByteArray(nextNALUnit); out.writeInt(data.length + 1);// w w w.ja va 2 s . c o m nu.write(out); out.write(data); return new Buffer(baos.toByteArray()); }
From source file:Main.java
public static byte[] createAuthenticationDigest(String passcode, long t1, double q1) throws IOException, NoSuchAlgorithmException { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); DataOutputStream out = new DataOutputStream(baos); byte[] digest = createDigest(passcode, t1, q1); out.writeLong(t1);/*w w w .j av a 2 s . co m*/ out.writeDouble(q1); out.writeInt(digest.length); out.write(digest); out.flush(); return baos.toByteArray(); }
From source file:org.apache.accumulo.core.crypto.CryptoUtils.java
/** * Write the decryption parameters to the DataOutputStream *///w w w . j a va 2 s. c o m public static void writeParams(byte[] decryptionParams, DataOutputStream out) throws IOException { Objects.requireNonNull(decryptionParams); Objects.requireNonNull(out); out.writeInt(decryptionParams.length); out.write(decryptionParams); }
From source file:de.cubeisland.engine.core.util.McUUID.java
private static HttpURLConnection postQuery(ArrayNode node, int page) throws IOException { HttpURLConnection con = (HttpURLConnection) new URL(MOJANG_API_URL_NAME_UUID + page).openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setUseCaches(false);/*from ww w . j a v a 2 s . co m*/ con.setDoInput(true); con.setDoOutput(true); DataOutputStream writer = new DataOutputStream(con.getOutputStream()); writer.write(node.toString().getBytes()); writer.close(); return con; }
From source file:com.shopgun.android.sdk.network.impl.HttpURLNetwork.java
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request) throws IOException { byte[] body = request.getBody(); if (body != null) { connection.setDoOutput(true);//w ww. j a v a2s . c om connection.addRequestProperty("Content-Type", request.getBodyContentType()); DataOutputStream out = new DataOutputStream(connection.getOutputStream()); out.write(body); out.close(); } }
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
public static void putString(DataOutputStream data, String str) throws IOException { // String ID is 1 data.writeByte(JSONKafkaSerializer.StringID); data.writeInt(str.length());//from ww w . j a v a2s. c om data.write(str.getBytes()); }
From source file:Decoder.java
public static String packLicense(byte[] text, byte[] hash) throws Exception { try {/* ww w . j a v a 2 s .c o m*/ ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream dOut = new DataOutputStream(out); dOut.writeInt(text.length); dOut.write(text); dOut.write(hash); byte[] allData = out.toByteArray(); String result = new String(Base64.encodeBase64(allData)).trim(); result = result + 'X' + "0" + 2 + Integer.toString(result.length(), 31); return split(result); } catch (IOException e) { throw new Exception(e); } }