当前位置: 首页>>代码示例>>Java>>正文


Java FSTObjectOutput.writeObject方法代码示例

本文整理汇总了Java中org.nustaq.serialization.FSTObjectOutput.writeObject方法的典型用法代码示例。如果您正苦于以下问题:Java FSTObjectOutput.writeObject方法的具体用法?Java FSTObjectOutput.writeObject怎么用?Java FSTObjectOutput.writeObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.nustaq.serialization.FSTObjectOutput的用法示例。


在下文中一共展示了FSTObjectOutput.writeObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Override
public void encode(Object obj, DataWriter out) throws IOException {
    try {
        FSTObjectOutput objOut = fst.getObjectOutput(out.asStream());

        objOut.writeObject(obj);
        objOut.flush();
    } catch (RuntimeException e) {
        // Workaround for FST throwing RuntimeException instead of NotSerializableException.
        if (e.getMessage() != null && e.getMessage().indexOf("does not implement Serializable") > 0) {
            NotSerializableException converted = new NotSerializableException(e.getMessage());

            converted.setStackTrace(e.getStackTrace());

            throw converted;
        } else {
            throw e;
        }
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:21,代码来源:FstCodec.java

示例2: FSWrite

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
private boolean FSWrite(String filepath, String tag) {
    try {
        if (!tag.equals("")) {
            tag = "_" + tag;
        }
        Logger.getRootLogger().info("Writing ID results to file:" + FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + tag + "_LCMSID.serFS...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + tag + "_LCMSID.serFS", false);
        FSTObjectOutput out = new FSTObjectOutput(fout);
        ReduceMemoryUsage();
        out.writeObject(this, LCMSID.class);
        out.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:19,代码来源:LCMSID.java

示例3: serializeCompressLZ4

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public synchronized int serializeCompressLZ4(T obj, File file) {
	try {
		byte[] barray = conf.get().asByteArray(obj);
		int compressedLength = barray.length;
		int decompressedLength = -1;
		// Notes: uses an LZ4 block size of 64KB, fast compressor 
		LZ4BlockOutputStream LZOS = new LZ4BlockOutputStream(new FileOutputStream(file));
		FSTObjectOutput oos = conf.get().getObjectOutput(LZOS);
		oos.writeObject(obj);
		oos.flush();
		LZOS.close();
		return decompressedLength;
	}
	catch(Exception e) {
		e.printStackTrace();
	}
	return -1;
}
 
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:19,代码来源:FSTDiskSerializer.java

示例4: main

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();

    SomeMediumClass mediumClass = new SomeMediumClass();
    byte barray[] = conf.asByteArray(mediumClass);
    System.out.println(barray.length);
    SomeMediumClass object = (SomeMediumClass)conf.asObject(barray);
    System.out.println(object);


    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    FSTObjectOutput output = new FSTObjectOutput(outputStream);
    output.writeObject(mediumClass);
    output.close();

    FSTObjectInput input = new FSTObjectInput(new ByteArrayInputStream(outputStream.toByteArray()));
    object = (SomeMediumClass)input.readObject(SomeMediumClass.class);
    System.out.println(object);
}
 
开发者ID:chuidiang,项目名称:chuidiang-ejemplos,代码行数:20,代码来源:FstExample.java

示例5: main

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    FSTConfiguration config = FSTConfiguration.createDefaultConfiguration();
    FSTObjectOutput out = config.getObjectOutput();
    out.writeObject("foobar");
    byte[] savedBuffer = out.getCopyOfWrittenBuffer();
    byte[] reallySavedBuffer = Arrays.copyOf(savedBuffer, savedBuffer.length);

    System.out.println(Arrays.equals(savedBuffer, reallySavedBuffer));

    out.resetForReUse();
    out.writeObject("blah");
    byte[] secondBuffer = out.getCopyOfWrittenBuffer();

    System.out.println(Arrays.equals(savedBuffer, reallySavedBuffer));

    config.getObjectInput(savedBuffer);
    config.getObjectInputCopyFrom(secondBuffer, 0, secondBuffer.length);
    System.out.println(Arrays.equals(savedBuffer, reallySavedBuffer));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:20,代码来源:Issue91.java

示例6: testStreamReuse

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Test
public void testStreamReuse() throws Exception {
    FSTConfiguration configuration = FSTConfiguration.createDefaultConfiguration();

    String expected = "Hello, World!";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FSTObjectOutput fstObjectOutput = configuration.getObjectOutput(baos);
    try {
        fstObjectOutput.writeObject(expected);
    } finally {
        fstObjectOutput.flush();
    }
    byte[] serializedData = baos.toByteArray();
    FSTObjectInput input = configuration.getObjectInput(new ByteArrayInputStream(serializedData));
    Object read = input.readObject();
    Assert.assertEquals(expected, read);

    FSTObjectInput secondInput = configuration.getObjectInput(new ByteArrayInputStream(new byte[0]));
    expectedException.expect(IOException.class);
    expectedException.expectMessage("Failed to read");
    secondInput.readObject();
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:23,代码来源:BasicReuseTest.java

示例7: testReadResolve

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Test
public void testReadResolve() throws Exception {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();

    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();

    checkEquals(Holder.class, res.getClass());
    checkEquals(String.class, ((Holder) res).o.getClass());
    checkEquals("foo", ((Holder) res).o);

    checkEquals(String.class, ((Holder) res).o2.getClass());
    checkEquals("foo", ((Holder) res).o2);
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:26,代码来源:ReadResolve.java

示例8: testWriteReplaceInList

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Test
public void testWriteReplaceInList() throws IOException, ClassNotFoundException {
	Container c = new Container();

	BaseClass b1 = new BaseClass();
	b1.value = "morphMe";
	c.list.add(b1);
	BaseClass b2 = new BaseClass();
	b2.value = "morphMe";
	c.list.add(b2);

	ByteArrayOutputStream buf = new ByteArrayOutputStream();
	FSTObjectOutput out = new FSTObjectOutput(buf, getTestConfiguration());
	out.writeObject(c);
	out.close();

	ObjectInput in = getTestConfiguration().getObjectInput(new ByteArrayInputStream(buf.toByteArray()));
	Container res = (Container) in.readObject();
	assertEquals("you have morphed", ((Morpher) res.list.get(0)).value);
	assertEquals("you have morphed", ((Morpher) res.list.get(1)).value);
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:22,代码来源:TestWriteReplaceInList.java

示例9: testHM

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Test
public void testHM() throws IOException, ClassNotFoundException {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
    HashMap hm = createHM();
    HashMap hm1 = createHM1(hm);
    FSTObjectOutput oo = conf.getObjectOutput();
    oo.writeObject(hm);
    oo.writeObject(hm1);
    byte[] copyOfWrittenBuffer = oo.getCopyOfWrittenBuffer();

    FSTObjectInput in = conf.getObjectInput(copyOfWrittenBuffer);
    Object o1 = in.readObject();
    Object o2 = in.readObject();
    Assert.assertTrue(DeepEquals.deepEquals(o1,hm));
    Assert.assertTrue(DeepEquals.deepEquals(o2,hm1));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:17,代码来源:BigObjTest.java

示例10: testWithStreams

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Test
public void testWithStreams() throws IOException, ClassNotFoundException {
    HashMap hm = createHM();
    HashMap hm1 = createHM1(hm);

    FSTObjectOutput out = new FSTObjectOutput(new FileOutputStream("../epsis.oos"));
    out.writeObject(hm);
    out.writeObject(hm1);
    out.close();

    FSTObjectInput in = new FSTObjectInput(new FileInputStream("../epsis.oos"));
    HashMap o1 = (HashMap) in.readObject();
    HashMap o2 = (HashMap) in.readObject();
    in.close();
    Assert.assertTrue(DeepEquals.deepEquals(o1, hm));
    Assert.assertTrue(DeepEquals.deepEquals(o2, hm1));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:18,代码来源:BigObjTest.java

示例11: encode

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Override
public ByteBuf encode(Object in) throws IOException {
    ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
    try {
        ByteBufOutputStream os = new ByteBufOutputStream(out);
        FSTObjectOutput oos = config.getObjectOutput(os);
        oos.writeObject(in);
        oos.flush();
        return os.buffer();
    } catch (IOException e) {
        out.release();
        throw e;
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:15,代码来源:FstCodec.java

示例12: LibraryMatchWrite

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public boolean LibraryMatchWrite() throws FileNotFoundException {
    try {
        Logger.getRootLogger().info("Writing Target match results to file:" + FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + "_" + LibID + "_LibMatch.serFS...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + "_" + LibID + "_LibMatch.serFS", false);
        FSTObjectOutput out = new FSTObjectOutput(fout);
        out.writeObject(this);
        out.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:15,代码来源:TargetMatchScoring.java

示例13: FasterSerialzationWrite

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public boolean FasterSerialzationWrite(String Filename) throws FileNotFoundException {
    try {
        org.apache.log4j.Logger.getRootLogger().info("Writing fasta serialization to file:" + FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer", false);
        FSTObjectOutput out = new FSTObjectOutput(fout);
        out.writeObject(this);
        out.close();
        fout.close();
    } catch (Exception ex) {
        org.apache.log4j.Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:15,代码来源:FastaParser.java

示例14: FSFragmentLibWrite

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
private void FSFragmentLibWrite(String path, String LibID1) {
    try {
        Logger.getRootLogger().info("Writing FragmentLib to file:" + path + LibID1 + ".serFS...");
        FileOutputStream fout = new FileOutputStream(path + LibID1 + ".serFS", false);
        FSTObjectOutput oos = new FSTObjectOutput(fout);
        oos.writeObject(this);
        oos.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:13,代码来源:FragmentLibManager.java

示例15: FS_PeakClusterWrite

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
private void FS_PeakClusterWrite() {
    try {
        Logger.getRootLogger().info("Writing PeakCluster serialization to file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS", false);
        FSTObjectOutput out = new FSTObjectOutput(fout);
        out.writeObject(PeakClusters);
        out.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        JavaSerializationPeakClusterWrite();
    }
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:14,代码来源:LCMSPeakBase.java


注:本文中的org.nustaq.serialization.FSTObjectOutput.writeObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。