本文整理匯總了Java中com.esotericsoftware.kryo.io.Output.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java Output.flush方法的具體用法?Java Output.flush怎麽用?Java Output.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.esotericsoftware.kryo.io.Output
的用法示例。
在下文中一共展示了Output.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serialize
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
/**
* 序列化
*
* @param obj 需要序更列化的對象
* @return 序列化後的byte 數組
* @throws TransactionException
*/
@Override
public byte[] serialize(Object obj) throws TransactionException {
byte[] bytes;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
//獲取kryo對象
Kryo kryo = new Kryo();
Output output = new Output(outputStream);
kryo.writeObject(output, obj);
bytes = output.toBytes();
output.flush();
} catch (Exception ex) {
throw new TransactionException("kryo serialize error" + ex.getMessage());
} finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
}
}
return bytes;
}
示例2: serialize
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
@Override
public byte[] serialize(Object obj) throws SerializerException {
byte[] bytes;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
//獲取kryo對象
Kryo kryo = new Kryo();
Output output = new Output(outputStream);
kryo.writeObject(output, obj);
bytes = output.toBytes();
output.flush();
} catch (Exception ex) {
throw new SerializerException("kryo serialize error" + ex.getMessage());
} finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
}
}
return bytes;
}
示例3: serialize
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
/**
* 序列化
*
* @param obj 需要序更列化的對象
* @return 序列化後的byte 數組
* @throws TccException
*/
@Override
public byte[] serialize(Object obj) throws TccException {
byte[] bytes;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
//獲取kryo對象
Kryo kryo = new Kryo();
Output output = new Output(outputStream);
kryo.writeObject(output, obj);
bytes = output.toBytes();
output.flush();
} catch (Exception ex) {
throw new TccException("kryo serialize error" + ex.getMessage());
}
return bytes;
}
示例4: encode
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf byteBuf) throws Exception {
if(clazz.isInstance(o)){
Kryo kryo = null;
try{
kryo = pool.borrow();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeObject(output, o);
output.flush();
output.close();
byte[] data = baos.toByteArray();
byteBuf.writeInt(data.length);
byteBuf.writeBytes(data);
baos.close();
}catch(Exception e){
LOG.warn("MessageEncoder happen exception.", e);
}finally{
if(kryo != null){
pool.release(kryo);
}
}
}
}
示例5: writeTable
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
private <E> void writeTable(String key, RakTable<E> paperTable, File originalFile, File backupFile) {
try {
FileOutputStream file = new FileOutputStream(originalFile);
final Output kryoOutput = new Output(file);
getKryo().writeObject(kryoOutput, paperTable);
kryoOutput.flush();
file.flush();
sync(file);
kryoOutput.close();
backupFile.delete();
} catch (IOException e) {
if (originalFile.exists()) {
if (!originalFile.delete()) {
throw new RuntimeException("cant deleted");
}
}
throw new RuntimeException("cant save to table " + key, e);
}
}
示例6: serialize
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
/**
* 序列化
*
* @param obj 需要序更列化的對象
* @return 序列化後的byte 數組
* @throws MythException 異常
*/
@Override
public byte[] serialize(Object obj) throws MythException {
byte[] bytes;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
//獲取kryo對象
Kryo kryo = new Kryo();
Output output = new Output(outputStream);
kryo.writeObject(output, obj);
bytes = output.toBytes();
output.flush();
} catch (Exception ex) {
throw new MythException("kryo serialize error" + ex.getMessage());
}
return bytes;
}
示例7: serialize
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
public byte[] serialize(Object object) {
Kryo kryo = new Kryo();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeObject(output, object);
output.flush();
output.close();
byte[] bytes = baos.toByteArray();
try {
baos.flush();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
示例8: serializationObject
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
private byte[] serializationObject(Kryo kryo, byte[] obj) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeClassAndObject(output, obj);
output.flush();
output.close();
byte[] b = baos.toByteArray();
try {
baos.flush();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
return b;
}
示例9: serializationObject
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
private <T extends Serializable> byte[] serializationObject(T obj) {
Kryo kryo = new Kryo();
kryo.setReferences(false);
kryo.register(obj.getClass(), new JavaSerializer());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeClassAndObject(output, obj);
output.flush();
output.close();
byte[] b = baos.toByteArray();
try {
baos.flush();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
return b;
}
示例10: serializeAlgoMetric
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
public static byte[] serializeAlgoMetric(Metric value) {
Kryo kryo = getKryo();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeClassAndObject(output, value);
output.flush();
output.close();
return baos.toByteArray();
}
示例11: encode
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
@Override
public CachedData encode(final Object obj) {
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
final Output output = new Output(byteStream);
kryo.writeClassAndObject(output, obj);
output.flush();
IOUtils.closeQuietly(output);
final byte[] bytes = byteStream.toByteArray();
return new CachedData(0, bytes, bytes.length);
}
示例12: clone
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
private <T> T clone(T obj){
Kryo kryo = kryoFactory.getKryo();
try {
Output output = new Output(1024, 1024 * 500);
kryo.writeClassAndObject(output, obj);
output.flush();
Input input = new Input(output.toBytes());
T t = (T) kryo.readClassAndObject(input);
return t;
} finally {
kryoFactory.returnKryo(kryo);;
}
}
示例13: treeNode
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
@Test
public void treeNode() {
final Result<DecisionTreeRuleSet> result = (new CommisionRuleSetSupplier()).get();
EhSupport.ensure(result.isSuccess(), "Could not create decision tree");
final DecisionTreeRuleSet ruleSet = result.getData();
final TreeNode node = DecisionTreeFactory.constructDecisionTree(ruleSet, DecisionTreeType.SINGLE);
final Kryo kryo = new Kryo();
// no default no-arg constructors
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
final InstantiatorStrategy defaultInstantiatorStrategy = new Kryo.DefaultInstantiatorStrategy();
kryo.getRegistration(ArrayList.class)
.setInstantiator(defaultInstantiatorStrategy.newInstantiatorOf(ArrayList.class));
kryo.getRegistration(HashSet.class)
.setInstantiator(defaultInstantiatorStrategy.newInstantiatorOf(HashSet.class));
UnmodifiableCollectionsSerializer.registerSerializers(kryo);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final Output output = new Output(out);
kryo.writeObject(output, node);
output.flush();
output.close();
final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray());
final Input kryoInput = new Input(inputStream);
final TreeNode tree = kryo.readObject(kryoInput, BaseTreeNode.class);
final SingleDecisionTreeFactoryTest test = new SingleDecisionTreeFactoryTest();
test.checkTreeNode(tree, ruleSet);
assertEquals(node, tree);
}
示例14: send
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
@Override
public void send(Output output) throws IOException {
output.writeInt(srcRank);
output.writeInt(destRank);
output.writeInt(step);
output.writeInt(sum);
output.writeInt(segNum);
for (int i = 0; i < segNum; i++) {
output.writeInt(ranks.get(i));
output.writeInt(dataNums.get(i));
}
output.flush();
}
示例15: send
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
@Override
public void send(Output output) throws IOException {
output.writeInt(srcRank);
output.writeInt(destRank);
output.writeInt(step);
output.writeInt(sum);
output.writeInt(segNum);
for (int i = 0; i < segNum; i++) {
output.writeInt(ranks.get(i));
output.writeInt(segFroms.get(i));
output.writeInt(segTos.get(i));
}
output.flush();
}