/** * The logic used here is based on java's DataInputStream.writeUTF() from the version 1.6.0_10. * * @param s * @return byte[] */ public static byte[] toUTF(String s) { HeapDataOutputStream hdos = new HeapDataOutputStream(s); return hdos.toByteArray(); }
public void testWriteByteBuffer() { HeapDataOutputStream out = new HeapDataOutputStream(32, Version.CURRENT); byte[] bytes = "1234567890qwertyuiopasdfghjklzxcvbnm,./;'".getBytes(); out.write(ByteBuffer.wrap(bytes, 0, 2)); out.write(ByteBuffer.wrap(bytes, 2, bytes.length - 2)); byte[] actual = out.toByteArray(); assertEquals(new String(bytes) , new String(actual)); }
public byte[] toBytes() throws IOException { HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT); sendTo(hdos); return hdos.toByteArray(); } public int compareTo(Object o) {
public byte[] toBytes() throws IOException { HeapDataOutputStream hdos = new HeapDataOutputStream(16, Version.CURRENT); sendTo(hdos); return hdos.toByteArray(); }
private byte[] serializeVersionTag(int entryVersion, long regionVersion, VersionSource versionMember, long timestamp, int dsId) throws IOException { HeapDataOutputStream out = new HeapDataOutputStream(4 + 8 + 4 + 8 + 4, Version.CURRENT); serializeVersionTag(entryVersion, regionVersion, versionMember, timestamp, dsId, out); byte[] versionsBytes = out.toByteArray(); return versionsBytes; }
public byte[] toBytes() throws IOException { HeapDataOutputStream hdos = new HeapDataOutputStream(16, Version.CURRENT); sendTo(hdos); return hdos.toByteArray(); }
public byte[] toBytes() throws IOException { HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT); sendTo(hdos); return hdos.toByteArray(); } public int compareTo(Object o) {
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 void testMonth() throws Exception { setupSerializer(false, false, "com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.MyMonth"); MyMonth m = new MyMonth(1); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(m, out); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(m, dObj); }
public void testExternalizable() throws Exception { setupSerializer("com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.MyExternalizable"); MyExternalizable o = new MyExternalizable(79); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(o, out); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(o, dObj); }
/** * A serializable with a writeReplace method should use standard serialization. */ public void testComparator() throws Exception { setupSerializer("com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.MyComparator"); TreeSet o = new TreeSet(new MyComparator()); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(o, out); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(o, dObj); }
private byte[] pmidToBytes(PersistentMemberID id) { try { HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT); InternalDataSerializer.invokeToData(id, hdos); return hdos.toByteArray(); } catch (IOException ex) { throw new DiskAccessException(LocalizedStrings.DiskInitFile_FAILED_INIT_FILE_WRITE_BECAUSE_0.toLocalizedString(ex), this.parent); } }
private byte[] pmidToBytes(PersistentMemberID id) { try { HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT); InternalDataSerializer.invokeToData(id, hdos); return hdos.toByteArray(); } catch (IOException ex) { throw new DiskAccessException(LocalizedStrings.DiskInitFile_FAILED_INIT_FILE_WRITE_BECAUSE_0.toLocalizedString(ex), this.parent); } }
private byte[] encryptId(long id, ServerConnection servConn) throws Exception { // deserialize this using handshake keys HeapDataOutputStream hdos = null; try { hdos = new HeapDataOutputStream(Version.CURRENT_GFE); hdos.writeLong(id); return ((HandShake)this.handshake).encryptBytes(hdos.toByteArray()); } finally { hdos.close(); } }
private byte[] encryptId(long id, ServerConnection servConn) throws Exception { // deserialize this using handshake keys HeapDataOutputStream hdos = null; try { hdos = new HeapDataOutputStream(Version.CURRENT); hdos.writeLong(id); return ((HandShake)this.handshake).encryptBytes(hdos.toByteArray()); } finally { hdos.close(); } }
public void testIsFieldIncluded() throws IOException, ClassNotFoundException { setupSerializer(new ExplicitIncludedAutoSerializer(false, "com.gemstone.gemfire.pdx.DomainObjectPdxAuto"), true); DomainObject objOut = new DomainObjectPdxAuto(4); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); PdxInstance pi = (PdxInstance)DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(true, pi.hasField("long_0")); assertEquals(false, pi.hasField("string_0")); } public static class ExplicitFieldNameAutoSerializer extends ReflectionBasedAutoSerializer {
public Object call() throws Exception { HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(new SimpleClass(57, (byte) 3), out); byte[] bytes = out.toByteArray(); Region r = getRootRegion("testSimplePdx"); r.put(1, bytes); return null; } });
protected static void writeServerMember(DistributedMember member, DataOutputStream dos) throws IOException { Version v = Version.CURRENT_GFE; if (dos instanceof VersionedDataStream) { v = ((VersionedDataStream) dos).getVersion(); } HeapDataOutputStream hdos = new HeapDataOutputStream(v); DataSerializer.writeObject(member, hdos); DataSerializer.writeByteArray(hdos.toByteArray(), dos); hdos.close(); }
protected static void writeServerMember(DistributedMember member, DataOutputStream dos) throws IOException { Version v = Version.CURRENT; if (dos instanceof VersionedDataStream) { v = ((VersionedDataStream) dos).getVersion(); } HeapDataOutputStream hdos = new HeapDataOutputStream(v); DataSerializer.writeObject(member, hdos); DataSerializer.writeByteArray(hdos.toByteArray(), dos); hdos.close(); }
public void testGetFieldName() throws IOException, ClassNotFoundException { setupSerializer(new ExplicitFieldNameAutoSerializer(false, "com.gemstone.gemfire.pdx.DomainObjectPdxAuto"), true); DomainObject objOut = new DomainObjectPdxAuto(4); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); PdxInstance pi = (PdxInstance)DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); System.out.println("fieldNames=" + pi.getFieldNames()); assertEquals(false, pi.hasField("long_0")); assertEquals(true, pi.hasField("_long_0")); assertEquals(true, pi.hasField("string_0")); assertEquals(objOut, pi.getObject()); }