public void write(DataOutputStream out) throws IOException { out.writeByte(tag); out.writeShort(memberName); out.writeShort(typeDescriptor); }
void write(DataOutputStream out) throws IOException { out.writeShort(name); out.writeInt(info.length); if (info.length > 0) out.write(info); }
/** Appends a name for the next object, array, or value. * @return this writer, for chaining */ public UBJsonWriter name (String name) throws IOException { if (current == null || current.array) throw new IllegalStateException("Current item must be an object."); byte[] bytes = name.getBytes("UTF-8"); if (bytes.length <= Byte.MAX_VALUE) { out.writeByte('i'); out.writeByte(bytes.length); } else if (bytes.length <= Short.MAX_VALUE) { out.writeByte('I'); out.writeShort(bytes.length); } else { out.writeByte('l'); out.writeInt(bytes.length); } out.write(bytes); named = true; return this; }
private static void initialize() { try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(byteOut); dout.writeShort(ObjectStreamConstants.STREAM_MAGIC); dout.writeShort(ObjectStreamConstants.STREAM_VERSION); HEADER = byteOut.toByteArray(); byteOut = new ByteArrayOutputStream(); dout = new DataOutputStream(byteOut); dout.writeByte(ObjectStreamConstants.TC_OBJECT); dout.writeByte(ObjectStreamConstants.TC_REFERENCE); dout.writeInt(ObjectStreamConstants.baseWireHandle); REPEATING_DATA = byteOut.toByteArray(); } catch(IOException e) { throw new Error("IOException: " + e.getMessage()); } }
private static byte[] getSerializedBytes(Class<?> clazz) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream data = new DataOutputStream(baos)) { data.writeShort(ObjectStreamConstants.STREAM_MAGIC); data.writeShort(ObjectStreamConstants.STREAM_VERSION); data.writeByte(ObjectStreamConstants.TC_OBJECT); data.writeByte(ObjectStreamConstants.TC_CLASSDESC); data.writeUTF(clazz.getName()); Long suid = getSerializableUID(clazz); data.writeLong(suid); data.writeByte(2); // classDescFlags (2 = Serializable) data.writeShort(0); // field count data.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); data.writeByte(ObjectStreamConstants.TC_NULL); } return baos.toByteArray(); }
@Deprecated static ByteBuffer toByteBufferV2(TransactionEventRecord record) { ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(512); DataOutputStream dataOutput = new DataOutputStream(byteOutput); try { dataOutput.writeInt(MAGIC_HEADER); dataOutput.writeShort(record.getRecordType()); dataOutput.writeLong(record.getTransactionID()); dataOutput.writeLong(record.getLogWriteOrderID()); record.write(dataOutput); dataOutput.flush(); // TODO toByteArray does an unneeded copy return ByteBuffer.wrap(byteOutput.toByteArray()); } catch (IOException e) { // near impossible throw Throwables.propagate(e); } finally { if (dataOutput != null) { try { dataOutput.close(); } catch (IOException e) { LOG.warn("Error closing byte array output stream", 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);
baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); dos.writeShort(new Short((short) value)); } catch (IOException e) { e.printStackTrace();
public void writeUTF (String s) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c > 0 && c < 80) { baos.write(c); } else if (c < '\u0800') { baos.write(0xc0 | (0x1f & (c >> 6))); baos.write(0x80 | (0x3f & c)); } else { baos.write(0xe0 | (0x0f & (c >> 12))); baos.write(0x80 | (0x3f & (c >> 6))); baos.write(0x80 | (0x3f & c)); } } writeShort(baos.count); os.write(baos.buf, 0, baos.count); } }
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)); }
private MethodInfo generateStaticInitializerCaller() throws IOException { MethodInfo minfo = new MethodInfo("<clinit>", "()V", ACC_STATIC); DataOutputStream out = new DataOutputStream(minfo.code); out.writeByte(opc_invokestatic); out.writeShort(cp.getMethodRef(dotToSlash(className), initMethodName, "()V")); out.writeByte(opc_return); minfo.declaredExceptions = new short[0]; return minfo; }
public void writeDeleteRequest(DataOutputStream outputStream, String storeName, ByteArray key, VectorClock version, RequestRoutingType routingType) throws IOException { StoreUtils.assertValidKey(key); outputStream.writeByte(VoldemortOpCode.DELETE_OP_CODE); outputStream.writeUTF(storeName); outputStream.writeBoolean(routingType.equals(RequestRoutingType.ROUTED)); if(protocolVersion > 1) { outputStream.writeByte(routingType.getRoutingTypeCode()); } outputStream.writeInt(key.length()); outputStream.write(key.get()); VectorClock clock = version; outputStream.writeShort(clock.sizeInBytes()); outputStream.write(clock.toBytes()); }
private static void writeLdc(LdcInsnNode lin, DataOutputStream dos) throws IOException { Object o = lin.cst; if (o instanceof Integer) { dos.writeShort(1); dos.writeInt((Integer)o); } else if (o instanceof Float) { dos.writeShort(2); dos.writeFloat((Float)o); } else if (o instanceof Long) { dos.writeShort(3); dos.writeLong((Long)o); } else if (o instanceof Double) { dos.writeShort(4); dos.writeDouble((Double)o); } else if (o instanceof String) { dos.writeShort(5); dos.writeUTF((String)o); } else if (o instanceof Type) { dos.writeShort(6); dos.writeUTF(((Type)o).getDescriptor()); } else { dos.writeShort(0); } }
public void write(String outPath) throws FileNotFoundException, IOException { offset = RECORD_LENGTH; traverse(root); try (DataOutputStream out = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(outPath)))) { out.writeLong(0x5e33); out.writeShort(RECORD_LENGTH); out.writeShort(root.children.size()); out.writeShort(0); offset = RECORD_LENGTH; write(root, out); } }
/** * Write this constant pool to a stream as part of the class file format. * * This consists of writing the "constant_pool_count" and "constant_pool[]" items of the "ClassFile" structure, * as described in JVMS section 4.1. */ public void write(OutputStream out) throws IOException { DataOutputStream dataOut = new DataOutputStream(out); // constant_pool_count: number of entries plus one dataOut.writeShort(pool.size() + 1); for (Entry e : pool) { e.write(dataOut); } }
/** For writing out the byte stream for this utf8 properly (incl size). */ public void writeBytes(DataOutputStream dd) throws IOException { int len; len = bytes.length; dd.writeShort(len - 2); dd.write(bytes, 2, len - 2); }
/** * Writes a tag. * * @param tag * The tag to write. * @throws IOException * if an I/O error occurs. */ public void writeNamedTag(String name, Tag tag) throws IOException { checkNotNull(name); checkNotNull(tag); int type = NBTUtils.getTypeCode(tag.getClass()); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); os.writeByte(type); os.writeShort(nameBytes.length); os.write(nameBytes); if (type == NBTConstants.TYPE_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
/** * Write an integer of this type to the given output stream */ public void write(DataOutputStream out, int value) throws IOException { switch (this) { case INT8: out.writeByte(value); break; case INT16: out.writeShort(value); break; case INT32: out.writeInt(value); break; default: throw new RuntimeException("Unknown itype: " + this); } }
void writeMemberToStream(GMSMember gmbr, DataOutputStream out) throws IOException { out.writeShort(Version.CURRENT_ORDINAL); out.writeInt(gmbr.getVmViewId()); out.writeLong(gmbr.getUuidLSBs()); out.writeLong(gmbr.getUuidMSBs()); out.flush(); }
int i, n; out.writeInt(0xCAFEBABE); // magic out.writeShort(minor); // minor version out.writeShort(major); // major version out.writeShort(accessFlags); out.writeShort(thisClass); out.writeShort(superClass); n = interfaces.length; out.writeShort(n); for (i = 0; i < n; ++i) out.writeShort(interfaces[i]); out.writeShort(n); for (i = 0; i < n; ++i) { FieldInfo finfo = (FieldInfo)list.get(i); out.writeShort(n); for (i = 0; i < n; ++i) { MethodInfo minfo = (MethodInfo)list.get(i); out.writeShort(attributes.size()); AttributeInfo.writeAll(attributes, out);