Package org.nustaq.serialization

Examples of org.nustaq.serialization.FSTObjectOutput


        conf.registerCrossPlatformClassMapping( new String[][] {
                        {"senum", "ser.Basics$SampleEnum"},
                        {"special", "ser.Basics$SpecialEnum"},
                }
        );
        out = new FSTObjectOutput(conf);
        in = new FSTObjectInput(conf);
    }
View Full Code Here


        @Test
        public void testCustomSerializer() throws Exception {
                FSTConfiguration FST = FSTConfiguration.createDefaultConfiguration();
                //FST.setForceSerializable(true);
                FST.registerSerializer(Bug34.NonSerializableClass.class, new Serializer(), false);
                FSTObjectOutput out = FST.getObjectOutput();
                out.writeObject(new Bug34.NonSerializableClass());

                FSTObjectInput in = FST.getObjectInput(out.getCopyOfWrittenBuffer());
                assertEquals(NonSerializableClass.class, in.readObject().getClass());
        }
View Full Code Here

            return dummy;
        }
    }

    public void exceptionTest(FSTConfiguration conf) throws IOException, ClassNotFoundException {
        FSTObjectOutput out = conf.getObjectOutput();
        Exception e;
        try {
            throw new Exception("Test");
        } catch (Exception ex) {
            e = ex;
        }
        out.writeObject(e);
        out.flush();
        FSTObjectInput in = new FSTObjectInput(conf);
        in.resetForReuseUseArray(out.getBuffer(),out.getWritten());
        Object ex = in.readObject();
        System.out.println("success "+ex);
    }
View Full Code Here

            exceptionTest(conf);

            ToWrite w = new ToWrite("bla");

            byte b[] = null;
            FSTObjectOutput out = new FSTObjectOutput(conf);
            out.writeObject(w);
            out.flush();
            b = out.getBuffer();

            FSTObjectInput in = new FSTObjectInput(conf);
            in.resetForReuseUseArray(b, b.length);
            Object res = in.readObject();
View Full Code Here

    protected FSTObjectOutput out;
    protected FSTObjectInput in;
   
    @org.junit.Before
    public void setUp() throws Exception {
        out = new FSTObjectOutput();
        in = new FSTObjectInput();
    }
View Full Code Here

    }

    @Test
    public void testFlush() throws IOException, ClassNotFoundException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream(1000*1000);
        FSTObjectOutput fout = new FSTObjectOutput(bout);
        Strings obj = new Strings();
        fout.writeObject(obj);
        fout.writeObject(new byte[1000*1000*10]);
        fout.writeObject(obj);
        fout.close();

        FSTObjectInput fin = new FSTObjectInput(new ByteArrayInputStream(bout.toByteArray()));
        Strings res = (Strings) fin.readObject();
        fin.readObject();
        Strings res1 = (Strings) fin.readObject();
View Full Code Here

    public void fastRoundTrip()
        throws IOException, ClassNotFoundException {
        TestArray list = new TestArray();

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        FSTObjectOutput objOut = new FSTObjectOutput(os);
        objOut.writeObject(list);
        objOut.close();

        ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
        FSTObjectInput objIn = new FSTObjectInput(is);
//        objIn.setReadExternalReadAHead(16000);
        TestArray res = (TestArray) objIn.readObject();
View Full Code Here

        Holder holder = new Holder();
        holder.o = new ToRead("foo");
        holder.o2 = holder.o;

        byte[] b = null;
        FSTObjectOutput out = new FSTObjectOutput(conf);
        out.writeObject(holder);
        out.flush();
        b = out.getBuffer();

        FSTObjectInput in = new FSTObjectInput(conf);
        in.resetForReuseUseArray(b,b.length);
        Object res = in.readObject();
View Full Code Here

   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
    try {
      if(useFst) {
        FSTObjectOutput out = fstConf.get().getObjectOutput(baos);
        out.writeObject(object);
      } else {
                getByteBuffer(object).position(0);
                getByteBuffer(object).putInt(9999);
                getByteBuffer(object).position(0);
                System.out.println("original object "+ extractFirstBufferField(object));
View Full Code Here

    }

    public void writeObject(Object toWrite) throws Exception {
        try {
            while ( !writeLock.compareAndSet(false,true) );
            FSTObjectOutput objectOutput = conf.getObjectOutput(); // could also do new with minor perf impact
            objectOutput.writeObject(toWrite);

            int written = objectOutput.getWritten();
            out.write((written >>> 0) & 0xFF);
            out.write((written >>> 8) & 0xFF);
            out.write((written >>> 16) & 0xFF);
            out.write((written >>> 24) & 0xFF);

            out.write(objectOutput.getBuffer(), 0, written);
            objectOutput.flush();
        } finally {
            writeLock.set(false);
        }
    }
View Full Code Here

TOP

Related Classes of org.nustaq.serialization.FSTObjectOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.