@Override public int available() { return size(); } @Override
public void setPartState(HeapDataOutputStream os, boolean isObject) { if (isObject) { this.typeCode = OBJECT_CODE; } else if (os != null && os.size() == 0) { this.typeCode = EMPTY_BYTEARRAY_CODE; } else { this.typeCode = BYTE_CODE; } this.part = os; } public byte getTypeCode() {
@Override public int available() { return size(); } @Override
public void setPartState(HeapDataOutputStream os, boolean isObject) { if (isObject) { this.typeCode = OBJECT_CODE; this.part = os; } else if (os != null && os.size() == 0) { this.typeCode = EMPTY_BYTEARRAY_CODE; this.part = EMPTY_BYTE_ARRAY; } else { this.typeCode = BYTE_CODE; this.part = os; } } public void setPartState(StoredObject so, boolean isObject) {
public int size() { return this.hdos.size(); }
/** * Return the length of the part. The length is the number of bytes needed * for its serialized form. */ public int getLength() { if (this.part == null) { return 0; } else if (this.part instanceof byte[]) { return ((byte[])this.part).length; } else { return ((HeapDataOutputStream)this.part).size(); } } public String getString() {
public int size() { return this.hdos.size(); }
/** * Return the length of the part. The length is the number of bytes needed * for its serialized form. */ public int getLength() { if (this.part == null) { return 0; } else if (this.part instanceof byte[]) { return ((byte[])this.part).length; } else if (this.part instanceof Chunk) { return ((Chunk) this.part).getValueSizeInBytes(); } else { return ((HeapDataOutputStream)this.part).size(); } } public String getString() {
/** * Writes the given object to this stream as a byte array. * The byte array is produced by serializing v. The serialization * is done by calling DataSerializer.writeObject. */ public void writeAsSerializedByteArray(Object v) throws IOException { if (v instanceof HeapDataOutputStream) { this.size += 4; // length is encoded as an int (or less) this.size += ((HeapDataOutputStream)v).size(); } else { this.size += 5; // length is encoded as a byte + an int DataSerializer.writeObject(v, this); } } }
/** * Writes the given object to this stream as a byte array. * The byte array is produced by serializing v. The serialization * is done by calling DataSerializer.writeObject. */ public void writeAsSerializedByteArray(Object v) throws IOException { if (v instanceof HeapDataOutputStream) { this.size += 4; // length is encoded as an int (or less) this.size += ((HeapDataOutputStream)v).size(); } else { this.size += 5; // length is encoded as a byte + an int DataSerializer.writeObject(v, this); } } }
/** * A blob is a serialized Object. This method serializes the * object into the given HeapDataOutputStream. */ public static void serializeTo(Object obj, HeapDataOutputStream hdos) throws IOException { final int startBytes = hdos.size(); final long start = startSerialization(); DataSerializer.writeObject(obj, hdos); endSerialization(start, hdos.size()-startBytes); }
/** * A blob is a serialized Object. This method serializes the * object into the given HeapDataOutputStream. */ public static void serializeTo(Object obj, HeapDataOutputStream hdos) throws IOException { final int startBytes = hdos.size(); final long start = startSerialization(); DataSerializer.writeObject(obj, hdos); endSerialization(start, hdos.size()-startBytes); }
private void doExtensible(String msg) throws IOException, ClassNotFoundException { BigInteger bi = new BigInteger("12345678901234567890"); BigDecimal bd = new BigDecimal("1234567890.1234567890"); BigHolder bih = new BigHolder(bi, bd); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(bih, out); System.out.println(msg + " out.size="+ out.size()); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(bih, dObj); }
private void doCHM(String msg) throws IOException, ClassNotFoundException { ConcurrentHashMap<String, BigHolder> chm = new ConcurrentHashMap<String, BigHolder>(); for (int i=1; i < 32; i++) { chm.put("key"+i, new BigHolder(i)); } CHMHolder h = new CHMHolder(chm); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(h, out); System.out.println(msg + " out.size=" + out.size()); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(h, dObj); }
public static int calculateBytesForTSandDSID(int dsid) { HeapDataOutputStream out = new HeapDataOutputStream(4 + 8, Version.CURRENT); long now = System.currentTimeMillis(); try { writeUnsignedVL(now, out); writeUnsignedVL(InternalDataSerializer.encodeZigZag64(dsid), out); } catch (IOException e) { return 0; } return out.size(); }
public final void sendTo(SocketChannel chan, ByteBuffer out) throws IOException { finishWriting(); if (size() == 0) { return; } if (this.chunks != null) { for (ByteBuffer bb: this.chunks) { sendChunkTo(bb, chan, out); } } sendChunkTo(this.buffer, chan, out); }
public static int calculateBytesForTSandDSID(int dsid) { HeapDataOutputStream out = new HeapDataOutputStream(4 + 8, Version.CURRENT); long now = System.currentTimeMillis(); try { writeUnsignedVL(now, out); writeUnsignedVL(InternalDataSerializer.encodeZigZag64(dsid), out); } catch (IOException e) { return 0; } return out.size(); }
@Override public int writeBytes(byte[] outBytes, int offset, DataTypeDescriptor dtd) { if (SanityManager.DEBUG) { SanityManager.ASSERT(!isNull(), "writeBytes() is not supposed to be called for null values."); } HeapDataOutputStream hdos = new HeapDataOutputStream(outBytes, offset, outBytes.length - offset); hdos.disallowExpansion(DISALLOW_EXPANSION); try { toDataForOptimizedResultHolder(hdos); } catch (IOException ioe) { throw GemFireXDRuntimeException.newRuntimeException( "Exception in UserType.writeBytes.", ioe); } return hdos.size(); }
@Override public int writeBytes(byte[] outBytes, int offset, DataTypeDescriptor dtd) { if (SanityManager.DEBUG) { SanityManager.ASSERT(!isNull(), "writeBytes() is not supposed to be called for null values."); } HeapDataOutputStream hdos = new HeapDataOutputStream(outBytes, offset, outBytes.length - offset); hdos.disallowExpansion(DISALLOW_EXPANSION); try { toDataForOptimizedResultHolder(hdos); } catch (IOException ioe) { throw GemFireXDRuntimeException.newRuntimeException( "Exception in UserType.writeBytes.", ioe); } return hdos.size(); }
@Override public int writeBytes(byte[] outBytes, int offset, DataTypeDescriptor dtd) { if (SanityManager.DEBUG) { SanityManager.ASSERT(!isNull(), "writeBytes() is not supposed to be called for null values."); } HeapDataOutputStream hdos = new HeapDataOutputStream(outBytes, offset, outBytes.length - offset); hdos.disallowExpansion(DISALLOW_EXPANSION); try { toDataForOptimizedResultHolder(hdos); } catch (IOException ioe) { throw GemFireXDRuntimeException.newRuntimeException( "Exception in UserType.writeBytes.", ioe); } return hdos.size(); }