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


Java FSTObjectOutput.flush方法代码示例

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


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

示例3: 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

示例4: 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

示例5: 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

示例6: serialize

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public synchronized void serialize(T obj, File file) {
	try {
		FileOutputStream fos = new FileOutputStream(file);
		BufferedOutputStream BOS = new BufferedOutputStream(fos);
		FSTObjectOutput oos = conf.get().getObjectOutput(BOS);
		oos.writeObject(obj);
		oos.flush();
		BOS.close();
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:14,代码来源:FSTDiskSerializer.java

示例7: serializeCompressGZIP

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public synchronized void serializeCompressGZIP(T obj, File file) {
	try {
		FileOutputStream fos =new FileOutputStream(file);
		BufferedOutputStream BOS = new BufferedOutputStream(
				new GZIPOutputStream(fos));
		FSTObjectOutput oos = conf.get().getObjectOutput(BOS);
		oos.writeObject(obj);
		oos.flush();
		BOS.close();
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:15,代码来源:FSTDiskSerializer.java

示例8: serializeCompressGZIP

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public byte[] serializeCompressGZIP(T obj){
	try {
		ByteArrayOutputStream byteStream=new ByteArrayOutputStream();
		BufferedOutputStream BOS = new BufferedOutputStream(
				new GZIPOutputStream(byteStream));
		FSTObjectOutput oos = conf.get().getObjectOutput(BOS);
		oos.writeObject(obj);
		oos.flush();
		BOS.close();
		return byteStream.toByteArray();
	}
	catch(Exception e) {
		return null;
	}
}
 
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:16,代码来源:FSTSerializerAndCompressor.java

示例9: serializeAndCompressAndWriteTargetToFile

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public void serializeAndCompressAndWriteTargetToFile(File file,
		T target, CompressionType compType) {
	try {
		// Open output stream to file
		FileOutputStream fos = new FileOutputStream(file);
		BufferedOutputStream BOS = new BufferedOutputStream(fos);
		FSTObjectOutput oos = conf.get().getObjectOutput(BOS);			
		// Switch on compression type to get byte array to write
		byte[] serialized = this.serialize(target);
		switch(compType) {
		case NONE:
			oos.write(serialized);
			//oos.writeObject(serialized);
			break;
		case LZ4:
			//int decompressedLength = serialized.length;
			//oos.writeInt(decompressedLength);
			//serialized = this.compressLZ4(serialized);
			oos.writeObject(serialized);
			break;
		case GZIP:
			serialized = this.compressGZIP(serialized);
			oos.writeObject(serialized);
		}
		// Close stream
		oos.flush();
		BOS.close();
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:33,代码来源:FSTSerializerAndCompressor.java

示例10: writeToFileFSTObject

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
/**
 * Writes a cache block to disk using FST object output streams
 * 
 * @param fileNumber The file number to write to
 * @param cacheSpot The block to write to disk
 * @param arrayList The BigArrayList
 * @throws IOException For I/O errors
 */
protected void writeToFileFSTObject(int fileNumber, int cacheSpot, BigArrayList<E> arrayList) throws IOException
{
	String filePath = memoryPath + File.separator + memoryInstance + "_memory_" + fileNumber + memoryExtension;

	File tempFile = new File(filePath);
	
	if(!arrayList.getList(cacheSpot).isEmpty())
	{
		tempFile.deleteOnExit();
	
		FileOutputStream fileOutputStream = new FileOutputStream(filePath);
		FSTObjectOutput fstObjectOutputStream = new FSTObjectOutput(fileOutputStream);

		try
		{
			byte byteArray[] = fstConfiguration.asByteArray(arrayList.getList(cacheSpot));
			fstObjectOutputStream.write(byteArray);
			fstObjectOutputStream.flush();
		}
		catch(IOException ioe)
		{
			throw ioe;
		}
		finally
		{
			fileOutputStream.close();
			fstObjectOutputStream.close();
		}
	}
	else
	{
		tempFile.delete();
	}
}
 
开发者ID:dselent,项目名称:BigArrayList,代码行数:43,代码来源:FileAccessor.java

示例11: writeObject

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public static void writeObject(OutputStream output, Object obj) throws IOException {
  FSTObjectOutput out = getFST().getObjectOutput(output);
  out.writeObject(obj);
  out.flush();
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:6,代码来源:Serializer.java

示例12: writeInt

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
public static void writeInt(OutputStream stream, int i) throws IOException {
	FSTObjectOutput out = conf.getObjectOutput(stream);
	out.writeInt(i);
	out.flush();
}
 
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:6,代码来源:FastSerializationUtil.java

示例13: streamedWrite

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的package包/类
@Override
protected void streamedWrite(OutputStream outputStream, T object) throws IOException {
    FSTObjectOutput out = get().getObjectOutput(outputStream);
    out.writeObject(object);
    out.flush();
}
 
开发者ID:lburgazzoli,项目名称:lb-hazelcast,代码行数:7,代码来源:FstSerializer.java


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