本文整理汇总了Java中org.apache.commons.lang.SerializationUtils.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java SerializationUtils.serialize方法的具体用法?Java SerializationUtils.serialize怎么用?Java SerializationUtils.serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.SerializationUtils
的用法示例。
在下文中一共展示了SerializationUtils.serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPatchForDependencies
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
private static void createPatchForDependencies() {
List<Plugin> pluginsList = pluginService.getAllPlugins();
for (Plugin plugin : pluginsList) {
ArrayList<Dependency> pluginDependencies = new ArrayList<Dependency>(plugin.getDependencies());
changePluginIdToName(pluginDependencies);
pluginNameVsDependencyMap.put(plugin.getPluginName(), pluginDependencies);
}
try {
File serializedExportFile = new File(upgradePatchFolderPath + File.separator + DataAccessConstant.DEPENDENCY_UPDATE
+ SERIALIZATION_EXT);
SerializationUtils.serialize(pluginNameVsDependencyMap, new FileOutputStream(serializedExportFile));
} catch (FileNotFoundException e) {
LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
}
}
示例2: reduce
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
public void reduce(Text keyname, Iterable<Text> str, Context context) throws IOException, InterruptedException {
if(analysis == null) analysis = new ResearcherMapReduceAnalysis(context.getConfiguration());
for(Text val : str) {
if(!(analysis.reduce(val.toString()) == true)) continue;
passNum++;
if(passNum % 10 == 0) System.gc();
}
// System.out.println("Final array: " + Arrays.toString((double[])analysis.serializer.serializeMe));
byte[] databyte = SerializationUtils.serialize(analysis.serializer);
String byte_to_string = Base64.encodeBase64String(databyte);
context.write(new Text("Run#" + passNum.toString()), new Text(byte_to_string));
}
示例3: put
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Override
public synchronized void put(T... datas) throws InterruptedException, ThorStoreException {
if (ArrayUtils.isEmpty(datas)) {
return;
}
FireQueue queue = getQueue();
if (queue == null) {
throw new ThorStoreException("FireQueue is null!");
}
for (T obj : datas) {
if (obj == null) {
continue;
}
byte[] byteDta = SerializationUtils.serialize(obj);
if (ArrayUtils.isEmpty(byteDta)) {
continue;
}
queue.push(byteDta);
this.notifyAll();
}
}
示例4: write
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Override
public void write(DataOutput output) throws IOException {
// write model type
WritableUtils.writeString(output, modelType);
// write learning rate
output.writeFloat(learningRate);
// write model path
if (this.modelPath != null) {
WritableUtils.writeString(output, modelPath);
} else {
WritableUtils.writeString(output, "null");
}
// serialize the class
Class<? extends FloatFeatureTransformer> featureTransformerCls = this.featureTransformer
.getClass();
byte[] featureTransformerBytes = SerializationUtils
.serialize(featureTransformerCls);
output.writeInt(featureTransformerBytes.length);
output.write(featureTransformerBytes);
}
示例5: methodReceived
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Override
public void methodReceived(AMQStateManager stateManager, DtxRecoverBodyImpl body, int channelId)
throws AMQException {
AMQProtocolSession session = stateManager.getProtocolSession();
AMQChannel channel = session.getChannel(channelId);
if (channel == null) {
throw body.getChannelNotFoundException(channelId);
}
try {
ArrayList<Xid> inDoubtXids = channel.recoverDtxTransactions();
MethodRegistry_0_91 methodRegistry = (MethodRegistry_0_91) session.getMethodRegistry();
byte[] serializedData = SerializationUtils.serialize(inDoubtXids);
DtxRecoverOkBody dtxRecoverOkBody = methodRegistry.createDtxRecoverOkBody(serializedData);
session.writeFrame(dtxRecoverOkBody.generateFrame(channelId));
} catch (DtxNotSelectedException e) {
throw body.getChannelException(AMQConstant.NOT_ALLOWED, "Not a distributed transacted session", e);
}
}
示例6: saveOrThrow
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
private static void saveOrThrow(final AnalysisResult analysisResult, final Resource resource) {
final SimpleAnalysisResult simpleAnalysisResult;
if (analysisResult instanceof SimpleAnalysisResult) {
simpleAnalysisResult = (SimpleAnalysisResult) analysisResult;
} else {
simpleAnalysisResult =
new SimpleAnalysisResult(analysisResult.getResultMap(), analysisResult.getCreationDate());
}
final OutputStream out = resource.write();
try {
SerializationUtils.serialize(simpleAnalysisResult, out);
} catch (final SerializationException e) {
logger.error("Error serializing analysis result: " + analysisResult, e);
throw e;
} finally {
FileHelper.safeClose(out);
}
}
示例7: train
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Override
public Model train(ModelConfig config, List<Object[]> instances) throws FOSException {
checkNotNull(instances, "Instances must be supplied");
checkNotNull(config, "Config must be supplied");
long time = System.currentTimeMillis();
WekaModelConfig wekaModelConfig = new WekaModelConfig(config, wekaManagerConfig);
Classifier classifier = WekaClassifierFactory.create(config);
FastVector attributes = WekaUtils.instanceFields2Attributes(wekaModelConfig.getClassIndex(), config.getAttributes());
InstanceSetter[] instanceSetters = WekaUtils.instanceFields2ValueSetters(config.getAttributes(), InstanceType.TRAINING);
Instances wekaInstances = new Instances(config.getProperty(WekaModelConfig.CLASSIFIER_IMPL), attributes, instances.size());
for (Object[] objects : instances) {
wekaInstances.add(WekaUtils.objectArray2Instance(objects, instanceSetters, attributes));
}
trainClassifier(wekaModelConfig.getClassIndex(), classifier, wekaInstances);
final byte[] bytes = SerializationUtils.serialize(classifier);
logger.debug("Trained model with {} instances in {}ms", instances.size(), (System.currentTimeMillis() - time));
return new ModelBinary(bytes);
}
示例8: Cloner
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
/**
* Creates a clonner by reading a serialized object from file.
*
* @param descriptor A {@link com.feedzai.fos.api.ModelDescriptor} with the information about the classifier.
* @throws IOException when there were problems reading the file
*/
public Cloner(ModelDescriptor descriptor) throws IOException {
checkNotNull(descriptor.getModelFilePath(), "Source file cannot be null");
File file = new File(descriptor.getModelFilePath());
checkArgument(file.exists(), "Source file '"+ file.getAbsolutePath() + "' must exist");
switch (descriptor.getFormat()) {
case BINARY:
this.serializedObject = FileUtils.readFileToByteArray(file);
break;
case PMML:
try {
this.serializedObject = SerializationUtils.serialize(PMMLConsumers.consume(file));
} catch (FOSException e) {
throw new RuntimeException("Failed to consume PMML file.", e);
}
break;
}
}
示例9: prepareForStore
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
/**
* This has to be called before this object will be persistet.
*/
public void prepareForStore(PersistenceBroker broker)
{
if(object != null)
{
if(useIdentity)
{
Identity oid = broker.serviceIdentity().buildIdentity(object);
this.oid = SerializationUtils.serialize(oid);
}
else
{
this.oid = SerializationUtils.serialize((Serializable) object);
}
}
}
示例10: testSerializationAndDeserialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
public void testSerializationAndDeserialization() throws Exception {
final NumberResult result1 = new NumberResult(42);
final AnalyzerResultFuture<NumberResult> future = new AnalyzerResultFuture<>("foo",
new ImmutableRef<NumberResult>(result1));
future.addListener(new Listener<NumberResult>() {
@Override
public void onSuccess(NumberResult result) {
// do nothing - this is just a non-serializable listener
}
@Override
public void onError(RuntimeException error) {
// do nothing - this is just a non-serializable listener
}
});
final byte[] bytes = SerializationUtils.serialize(future);
final AnalyzerResultFuture<?> copy = (AnalyzerResultFuture<?>) SerializationUtils.deserialize(bytes);
assertEquals("foo", copy.getName());
assertEquals("42", copy.get().toString());
}
示例11: javaSer
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
public void javaSer() {
long begin = System.currentTimeMillis();
int length = 0;
for (int i = 0; i < LOOP_COUNT; ++i) {
byte[] bytes = SerializationUtils.serialize(mkTestDates(SIZE));
length = bytes.length;
}
long time = System.currentTimeMillis() - begin;
System.out.println("java time " + time + ", len " + length);
}
示例12: getRealSize
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
private int getRealSize() {
int size = super.calcPacketSize();
for (int i = 0; i < sumSize; i++) {
byte[] v = null;
Object obj = sumTranObjects[i];
if (obj != null)
v = SerializationUtils.serialize((Serializable) obj);
size += (v == null || v.length == 0) ? 1 : ByteUtil.decodeLength(v);
}
return size;
}
示例13: toBytes
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Override
public byte[] toBytes() {
int size = getRealSize();
ByteBuffer buffer = DbleServer.getInstance().getBufferPool().allocate(size + PACKET_HEADER_SIZE);
BufferUtil.writeUB3(buffer, size);
buffer.put(packetId);
for (int i = 0; i < this.sumSize; i++) {
Object obj = sumTranObjects[i];
byte[] ov = null;
if (obj != null)
ov = SerializationUtils.serialize((Serializable) obj);
if (ov == null) {
buffer.put(NULL_MARK);
} else if (ov.length == 0) {
buffer.put(EMPTY_MARK);
} else {
BufferUtil.writeWithLength(buffer, ov);
}
}
for (int i = 0; i < this.getFieldCount(); i++) {
byte[] fv = fieldValues.get(i);
if (fv == null) {
buffer.put(NULL_MARK);
} else if (fv.length == 0) {
buffer.put(EMPTY_MARK);
} else {
BufferUtil.writeWithLength(buffer, fv);
}
}
buffer.flip();
byte[] data = new byte[buffer.limit()];
buffer.get(data);
DbleServer.getInstance().getBufferPool().recycle(buffer);
return data;
}
示例14: createStub
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Override
public LuaCompoundIdentifierStub createStub(@NotNull LuaCompoundIdentifier psi, StubElement parentStub) {
final LuaType luaType = psi.getLuaType();
final byte[] bytes = luaType instanceof LuaPrimitiveType ? null : SerializationUtils.serialize(luaType);
final boolean declaration = psi.isCompoundDeclaration() && psi.getScopeIdentifier() instanceof LuaGlobal;
return new LuaCompoundIdentifierStubImpl(parentStub, StringRef.fromNullableString(psi.getName()), declaration, bytes, luaType);
}
示例15: createStub
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Override
public LuaModuleDeclarationStub createStub(@NotNull LuaModuleExpression psi, StubElement parentStub) {
log.debug(psi.getText());
final String moduleName = psi.getModuleName();
return new LuaModuleDeclarationStubImpl(parentStub, StringRef.fromNullableString(psi.getName()), StringRef.fromNullableString(moduleName),
SerializationUtils.serialize(psi.getLuaType()));
}