public void write(DataOutputStream out) throws IOException { out.writeByte(tag); out.writeByte(refKind); out.writeShort(refIndex); }
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()); } }
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); DataOutputStream out = new DataOutputStream(baos); out.writeLong(l); out.writeShort(count); out.writeByte(tag); switch(tag) { case 0: out.writeInt(in.readInt()); break; case 6: // CONSTANT_Double out.writeLong(in.readLong()); break; out.writeShort(in.readShort()); break; int len; while((len=in.read(buf))>0) out.write(buf,0,len); return baos.toByteArray();
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(); }
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); } }
public GFSnapshotExporter(File out, String region, InternalCache cache) throws IOException { this.cache = cache; FileOutputStream fos = new FileOutputStream(out); fc = fos.getChannel(); dos = new DataOutputStream(new BufferedOutputStream(fos)); // write snapshot version dos.writeByte(SNAP_VER_2); // write format type dos.write(SNAP_FMT); // write temporary pdx location in bytes 4-11 dos.writeLong(-1); // write region name dos.writeUTF(region); }
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)); }
/** * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java * serialization). This has been measured to save at least 400 bytes compared to regular * serialization. * * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter. */ public void writeTo(OutputStream out) throws IOException { // Serial form: // 1 signed byte for the strategy // 1 unsigned byte for the number of hash functions // 1 big endian int, the number of longs in our bitset // N big endian longs of our bitset DataOutputStream dout = new DataOutputStream(out); dout.writeByte(SignedBytes.checkedCast(strategy.ordinal())); dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor dout.writeInt(bits.data.length()); for (int i = 0; i < bits.data.length(); i++) { dout.writeLong(bits.data.get(i)); } }
public void writeGetVersionRequest(DataOutputStream output, String storeName, ByteArray key, RequestRoutingType routingType) throws IOException { StoreUtils.assertValidKey(key); output.writeByte(VoldemortOpCode.GET_VERSION_OP_CODE); output.writeUTF(storeName); output.writeBoolean(routingType.equals(RequestRoutingType.ROUTED)); if(protocolVersion > 1) { output.writeByte(routingType.getRoutingTypeCode()); } output.writeInt(key.length()); output.write(key.get()); }
/** 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; }
PrimitiveObjectInspector oi) throws IOException { DataOutputStream dos = new DataOutputStream(out); dos.writeByte(bt); break; dos.writeShort(s); break; dos.writeInt(i); break; dos.writeLong(l); break;
public void save(OutputStream output) throws IOException { try (DataOutputStream out = new DataOutputStream(output)) { out.writeBytes(JADX_CLS_SET_HEADER); out.writeByte(VERSION); LOG.info("Classes count: {}", classes.length); out.writeInt(classes.length); for (NClass cls : classes) { writeString(out, cls.getName()); } for (NClass cls : classes) { NClass[] parents = cls.getParents(); out.writeByte(parents.length); for (NClass parent : parents) { out.writeInt(parent.getId()); } } } }
public void write(DataOutputStream out) throws IOException { if (value instanceof String) { out.writeByte(CONSTANT_UTF8); out.writeUTF((String) value); } else if (value instanceof Integer) { out.writeByte(CONSTANT_INTEGER); out.writeInt(((Integer) value).intValue()); } else if (value instanceof Float) { out.writeByte(CONSTANT_FLOAT); out.writeFloat(((Float) value).floatValue()); } else if (value instanceof Long) { out.writeByte(CONSTANT_LONG); out.writeLong(((Long) value).longValue()); } else if (value instanceof Double) { out.writeDouble(CONSTANT_DOUBLE); out.writeDouble(((Double) value).doubleValue()); } else { throw new InternalError("bogus value entry: " + value); } } }
os.writeByte((byte) tag.getValue()); break; os.writeShort((short) tag.getValue()); break; os.writeInt((int) tag.getValue()); break; os.writeLong((long) tag.getValue()); break; os.writeInt(bytes.length); os.write(bytes); break; List<Tag> tags = listTag.getValue(); os.writeByte(listTag.getChildType().getId()); os.writeInt(tags.size()); for (Tag child : tags) { writeTagPayload(child); writeTag(entry.getKey(), entry.getValue()); os.writeByte((byte) 0); // end tag break;
public void test(OutputStream output) throws IOException { DataOutputStream out = new DataOutputStream(output); try { out.writeByte(1); out.writeInt(classes.length); for (NClass cls : classes) { writeString(out, cls.getName()); } for (NClass cls : classes) { NClass[] parents = cls.getParents(); out.writeByte(parents.length); for (NClass parent : parents) { out.writeInt(parent.getId()); } } } finally { out.close(); } }
/** * 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); }