本文整理汇总了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;
}
}
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}