本文整理匯總了Java中com.esotericsoftware.kryo.io.Output.toBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java Output.toBytes方法的具體用法?Java Output.toBytes怎麽用?Java Output.toBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.esotericsoftware.kryo.io.Output
的用法示例。
在下文中一共展示了Output.toBytes方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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;
}
示例5: serialize
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
@Override
public byte[] serialize(Object[] objects) {
Output output = new Output(DEFAULT_BUFFER_SIZE, -1);
Kryo kryo = pool.borrow();
kryo.writeObjectOrNull(output, objects, Object[].class);
pool.release(kryo);
return output.toBytes();
}
示例6: serialize
import com.esotericsoftware.kryo.io.Output; //導入方法依賴的package包/類
public byte[] serialize(T t) {
Kryo kryo = kryoFactory.getKryo();
try {
Output output = new Output(1024, 1024 * 500);
kryo.writeClassAndObject(output, t);
return output.toBytes();
} finally {
kryoFactory.returnKryo(kryo);
kryo = null;
}
}
示例7: 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);;
}
}