@Override protected void writeToStream(DataOutputStream output) throws IOException { output.writeUTF(uri.toString()); output.writeBoolean(isRemoveAction); output.writeInt(data.length); output.write(data); boolean customCacheKeySet = customCacheKey != null; output.writeBoolean(customCacheKeySet); if (customCacheKeySet) { output.writeUTF(customCacheKey); } }
private void sendMessage() throws IOException { dataOut.flush(); byte[] buff = outBuffer.toByteArray(); int len = buff.length; dataOut = new DataOutputStream(out); dataOut.write(messageType); dataOut.writeInt(len + 4); dataOut.write(buff); dataOut.flush(); }
/** * 输出参数 * * @param conn * @param method * @param requestParams * @throws IOException */ private void outputParam(HttpURLConnection conn, String method, String requestParams, String encoding) throws IOException { //写入参数 if (requestParams != null && !"".equals(requestParams)) { DataOutputStream writer = new DataOutputStream(conn.getOutputStream()); logger.debug("Request out method " + method + ",out parameters " + requestParams); writer.write(requestParams.getBytes(encoding)); writer.flush(); writer.close(); } }
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); out.writeDouble(q1); out.writeInt(digest.length); out.write(digest); out.flush(); return baos.toByteArray(); }
ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class try { in = new DataOutputStream(bIn); in.write(MAGIC); in.write(VERSION); in.writeShort(CONSTANT_POOL_COUNT); in.writeInt(CODE_ATTRIBUTE_LENGTH); // attribute length in.writeShort(1); // max_stack in.writeShort(1); // max_locals in.writeInt(CODE.length); // code length in.write(CODE); in.writeShort(0); // exception_table_length = 0 in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable if(in != null) { try { in.close(); } catch (IOException e) { throw new ObjenesisException(e); return bIn.toByteArray();
public static byte[] encodeDelegationTokenInformation(DelegationTokenInformation token) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bos); WritableUtils.writeVInt(out, token.password.length); out.write(token.password); out.writeLong(token.renewDate); out.flush(); return bos.toByteArray(); } catch (IOException ex) { throw new RuntimeException("Failed to encode token.", ex); } }
public byte[] getBytes() { try { ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); DataOutputStream output = new DataOutputStream(byteOutput); output.writeByte(opCode); if(opCode != VoldemortOpCode.GET_OP_CODE) output.write(version.toBytes()); output.writeUTF(key); if(opCode == VoldemortOpCode.PUT_OP_CODE) { output.writeInt(value.length); output.write(value); } return byteOutput.toByteArray(); } catch(IOException e) { throw new SerializationException(e); } }
@Test public void testReads() throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(100); DataOutputStream dos = new DataOutputStream(bos); String s = "test"; int i = 128; dos.write(1); dos.writeInt(i); dos.writeBytes(s); dos.writeLong(12345L); dos.writeShort(2); dos.flush(); ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray()); bbis.close(); bb = ByteBuffer.wrap(bos.toByteArray()); bbis = new ByteBuffInputStream(new MultiByteBuff(bb)); DataInputStream dis = new DataInputStream(bbis);
private static void doTestSerializationV0RoundTrip(HlsDownloadAction action) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream output = new DataOutputStream(out); DataOutputStream dataOutputStream = new DataOutputStream(output); dataOutputStream.writeUTF(action.type); dataOutputStream.writeInt(/* version */ 0); dataOutputStream.writeUTF(action.uri.toString()); dataOutputStream.writeBoolean(action.isRemoveAction); dataOutputStream.writeInt(action.data.length); dataOutputStream.write(action.data); dataOutputStream.writeInt(action.keys.size()); for (int i = 0; i < action.keys.size(); i++) { StreamKey key = action.keys.get(i); dataOutputStream.writeInt(key.groupIndex); dataOutputStream.writeInt(key.trackIndex); } dataOutputStream.flush(); assertEqual(action, deserializeActionFromStream(out)); }
@Test public void test() throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Meter meter = new Meter(); MeteredOutputStream mos = MeteredOutputStream.builder().out(outputStream).meter(meter).updateFrequency(1).build(); MyOutputStream duplicated = new MyOutputStream(mos); DataOutputStream dos = new DataOutputStream(duplicated); dos.write("abcde".getBytes(Charsets.UTF_8)); Assert.assertEquals(outputStream.toString(Charsets.UTF_8.name()), "aabbccddee"); Optional<MeteredOutputStream> meteredOutputStream = MeteredOutputStream.findWrappedMeteredOutputStream(dos); Assert.assertEquals(meteredOutputStream.get(), mos); Assert.assertEquals(meteredOutputStream.get().getBytesProcessedMeter().getCount(), 10); }
writeUnsignedInt(dataOutputStream, duration); writeUnsignedInt(dataOutputStream, eventMessage.id); dataOutputStream.write(eventMessage.messageData); dataOutputStream.flush(); return byteArrayOutputStream.toByteArray(); } catch (IOException e) {
private static String createBodyFile(MessageExt msg) throws IOException { DataOutputStream dos = null; try { String bodyTmpFilePath = "/tmp/rocketmq/msgbodys"; File file = new File(bodyTmpFilePath); if (!file.exists()) { file.mkdirs(); } bodyTmpFilePath = bodyTmpFilePath + "/" + msg.getMsgId(); dos = new DataOutputStream(new FileOutputStream(bodyTmpFilePath)); dos.write(msg.getBody()); return bodyTmpFilePath; } finally { if (dos != null) dos.close(); } }
/** Writes the ETC1Data with a PKM header to the given file. * @param file the file. */ public void write (FileHandle file) { DataOutputStream write = null; byte[] buffer = new byte[10 * 1024]; int writtenBytes = 0; compressedData.position(0); compressedData.limit(compressedData.capacity()); try { write = new DataOutputStream(new GZIPOutputStream(file.write(false))); write.writeInt(compressedData.capacity()); while (writtenBytes != compressedData.capacity()) { int bytesToWrite = Math.min(compressedData.remaining(), buffer.length); compressedData.get(buffer, 0, bytesToWrite); write.write(buffer, 0, bytesToWrite); writtenBytes += bytesToWrite; } } catch (Exception e) { throw new GdxRuntimeException("Couldn't write PKM file to '" + file + "'", e); } finally { StreamUtils.closeQuietly(write); } compressedData.position(dataOffset); compressedData.limit(compressedData.capacity()); }
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); try (OutputStream gzos = new GZIPOutputStream(buf); ObjectOutputStream oos = JenkinsJVM.isJenkinsJVM() ? AnonymousClassWarnings.checkingObjectOutputStream(gzos) : new ObjectOutputStream(gzos)) { oos.writeObject(this); } ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); try { buf2.write(PREAMBLE); if (JenkinsJVM.isJenkinsJVM()) { // else we are in another JVM and cannot sign; result will be ignored unless INSECURE byte[] mac = MAC.mac(buf.toByteArray()); dos.writeInt(- mac.length); // negative to differentiate from older form dos.write(mac); } dos.writeInt(buf.size()); buf.writeTo(dos); } finally { dos.close(); } buf2.write(POSTAMBLE); return buf2; }
/** * Outputs the data in wav format. * * @param fileName * file name * @param sampleRate * sample rate * @throws IOException * IOException */ private void doWrite(String fileName, int sampleRate) throws IOException { DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName))); dos.writeBytes("RIFF"); // "RIFF" in ascii dos.writeInt(byteswap(36 + buf.length)); // Chunk size dos.writeBytes("WAVEfmt "); dos.writeInt(byteswap(16)); // chunk size, 16 for PCM dos.writeShort(byteswap((short) 1)); // PCM format dos.writeShort(byteswap((short) 1)); // Mono, one channel dos.writeInt(byteswap(sampleRate)); // Samplerate dos.writeInt(byteswap(sampleRate * nBytesPerSample)); // Byte-rate dos.writeShort(byteswap((short) (nBytesPerSample))); // Nbr of bytes per samples x nbr of channels dos.writeShort(byteswap((short) (nBytesPerSample * 8))); // nbr of bits per sample dos.writeBytes("data"); dos.writeInt(byteswap(buf.length)); dos.write(buf); // <= This buffer should already be byte-swapped at this stage dos.close(); }
private void initializeData(DataOutputStream out) throws IOException { /* Write out various test values NORMALLY */ out.write(new byte[] {-100, 100}); out.writeBoolean(true); out.writeBoolean(false); out.writeByte(100); out.writeByte(-100); out.writeByte((byte) 200); out.writeChar('a'); out.writeShort((short) -30000); out.writeShort((short) 50000); out.writeInt(0xCAFEBABE); out.writeLong(0xDEADBEEFCAFEBABEL); out.writeUTF("Herby Derby"); out.writeFloat(Float.intBitsToFloat(0xCAFEBABE)); out.writeDouble(Double.longBitsToDouble(0xDEADBEEFCAFEBABEL)); }
protected void write(CommandArguments args, AbstractCommand command) { try { Document document = xmlBuilder.newDocument(); command.run(this, args, document); StringWriter xmlWriter = new StringWriter(); StreamResult xmlResult = new StreamResult(xmlWriter); transformer.transform(new DOMSource(document), xmlResult); byte[] xmlBytes = xmlWriter.toString().getBytes(); DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); out.write(String.valueOf(xmlBytes.length).getBytes()); out.write("\0".getBytes()); out.write(xmlBytes); out.write("\0".getBytes()); out.flush(); } catch (IOException | TransformerException e) { throw new DebuggerException(e); } }