Java Code Examples for org.apache.commons.lang.SerializationUtils#serialize()
The following examples show how to use
org.apache.commons.lang.SerializationUtils#serialize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesResource.java From onedev with MIT License | 6 votes |
@Path("/job-context") @Produces(MediaType.APPLICATION_OCTET_STREAM) @GET public byte[] getJobContext() { JobContext context = jobManager.getJobContext(getJobToken(), true); Map<String, Object> contextMap = new HashMap<>(); contextMap.put("commands", context.getCommands()); contextMap.put("retrieveSource", context.isRetrieveSource()); contextMap.put("cloneDepth", context.getCloneDepth()); contextMap.put("projectName", context.getProjectName()); contextMap.put("cloneInfo", context.getCloneInfo()); contextMap.put("commitHash", context.getCommitId().name()); contextMap.put("collectFiles.includes", context.getCollectFiles().getIncludes()); contextMap.put("collectFiles.excludes", context.getCollectFiles().getExcludes()); return SerializationUtils.serialize((Serializable) contextMap); }
Example 2
Source File: ParamSupply.java From onedev with MIT License | 6 votes |
@SuppressWarnings("unchecked") public static Class<? extends Serializable> defineBeanClass(Collection<ParamSpec> paramSpecs) { byte[] bytes = SerializationUtils.serialize((Serializable) paramSpecs); String className = PARAM_BEAN_PREFIX + "_" + Hex.encodeHexString(bytes); List<ParamSpec> paramSpecsCopy = new ArrayList<>(paramSpecs); for (int i=0; i<paramSpecsCopy.size(); i++) { ParamSpec paramSpec = paramSpecsCopy.get(i); if (paramSpec instanceof SecretParam) { ParamSpec paramSpecClone = (ParamSpec) SerializationUtils.clone(paramSpec); String description = paramSpecClone.getDescription(); if (description == null) description = ""; description += String.format("<div style='margin-top: 12px;'><b>Note:</b> Secret less than %d characters " + "will not be masked in build log</div>", SecretInput.MASK.length()); paramSpecClone.setDescription(description); paramSpecsCopy.set(i, paramSpecClone); } } return (Class<? extends Serializable>) ParamSpec.defineClass(className, "Build Parameters", paramSpecsCopy); }
Example 3
Source File: MemcachedClientTest.java From ob1k with Apache License 2.0 | 6 votes |
@Test(expected = ExecutionException.class) public void testMultiget_TranscoderExecption() throws ExecutionException, InterruptedException, TimeoutException { final Transcoder<Serializable> transcoder = new Transcoder<Serializable>() { @Override public Serializable decode(final byte[] b) { throw new SerializationException("QQQQQ YYYYY"); } @Override public byte[] encode(final Serializable t) { return SerializationUtils.serialize(t); } }; final MemcachedClient<Object, Serializable> client = createClient(transcoder); client.setAsync("meh", "its here").get(); client.getBulkAsync(Lists.newArrayList("meh", "bah")).get(1, TimeUnit.MINUTES); }
Example 4
Source File: AbstractNeuralNetwork.java From incubator-retired-horn with Apache License 2.0 | 6 votes |
@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); }
Example 5
Source File: NodeMonitoring.java From ankush with GNU Lesser General Public License v3.0 | 5 votes |
/** * Method to set graph view data. * * @param graphViewData */ public void setGraphViewData(HashMap graphViewData) { // if graphViewData is not null. if (graphViewData != null) { this.graphView = SerializationUtils.serialize(graphViewData); } }
Example 6
Source File: RemoteApiVersionTest.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void testSerial() { SerializationUtils.serialize(RemoteApiVersion.unknown()); final RemoteApiVersion remoteApiVersion = RemoteApiVersion.create(1, 20); final byte[] serialized = SerializationUtils.serialize(remoteApiVersion); RemoteApiVersion deserialized = (RemoteApiVersion) SerializationUtils.deserialize(serialized); assertThat("Deserialized object mush match source object", deserialized, equalTo(remoteApiVersion)); }
Example 7
Source File: DefaultDockerClientConfigTest.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void serializableTest() { final byte[] serialized = SerializationUtils.serialize(EXAMPLE_CONFIG); final DefaultDockerClientConfig deserialized = (DefaultDockerClientConfig) SerializationUtils.deserialize(serialized); assertThat("Deserialized object mush match source object", deserialized, equalTo(EXAMPLE_CONFIG)); }
Example 8
Source File: SalesforceInputTestIT.java From components with Apache License 2.0 | 5 votes |
@Test public void testSerialization() throws IOException { SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForModule(); properties.getDatasetProperties().selectColumnIds.setValue(Arrays.asList("IsDeleted", "Id")); SalesforceDataprepSource source = new SalesforceDataprepSource(); source.initialize(null, properties); source.getConnectionHolder(); SerializationUtils.serialize(source); }
Example 9
Source File: StormParserDriver.java From metron with Apache License 2.0 | 5 votes |
public ProcessorResult<List<byte[]>> run(Iterable<byte[]> in) { ShimParserBolt bolt = new ShimParserBolt(new ArrayList<>()); byte[] b = SerializationUtils.serialize(bolt); ShimParserBolt b2 = (ShimParserBolt) SerializationUtils.deserialize(b); OutputCollector collector = mock(OutputCollector.class); bolt.prepare(null, null, collector); for(byte[] record : in) { Tuple tuple = toTuple(record); bolt.execute(tuple); verify(collector, times(1)).ack(tuple); } return bolt.getResults(); }
Example 10
Source File: SpanTest.java From wingtips with Apache License 2.0 | 5 votes |
@Test public void span_serializes_and_deserializes_with_no_data_loss() { Span span = new Span( traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId, spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan, startTimeNanosForFullyCompleteSpan, durationNanosForFullyCompletedSpan, tags, annotations ); byte[] bytes = SerializationUtils.serialize(span); Span deserializedSpan = (Span) SerializationUtils.deserialize(bytes); verifySpanDeepEquals(span, deserializedSpan, false); }
Example 11
Source File: DGRowPacket.java From dble with GNU General Public License v2.0 | 5 votes |
@Override public byte[] toBytes() { int size = getRealSize(); ByteBuffer buffer = BufferPoolManager.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); BufferPoolManager.getBufferPool().recycle(buffer); return data; }
Example 12
Source File: DGRowPacket.java From dble with GNU General Public License v2.0 | 5 votes |
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; }
Example 13
Source File: KubernetesResource.java From onedev with MIT License | 5 votes |
@Path("/allocate-job-caches") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM) @POST public byte[] allocateJobCaches(byte[] cacheAllocationRequestBytes) { CacheAllocationRequest allocationRequest = (CacheAllocationRequest) SerializationUtils .deserialize(cacheAllocationRequestBytes); return SerializationUtils.serialize((Serializable) jobManager.allocateJobCaches( getJobToken(), allocationRequest.getCurrentTime(), allocationRequest.getInstances())); }
Example 14
Source File: TranslationOperation.java From modernmt with Apache License 2.0 | 4 votes |
@Override protected void writeInternal(ObjectDataOutput out) throws IOException { byte[] taskBytes = SerializationUtils.serialize(this.task); out.writeByteArray(taskBytes); }
Example 15
Source File: JavaSerialization.java From api-mining with GNU General Public License v3.0 | 4 votes |
@Override public byte[] serialize(Object obj) throws SerializationException { return SerializationUtils.serialize((Serializable) obj); }
Example 16
Source File: JavaSerialization.java From tassal with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public byte[] serialize(Object obj) throws SerializationException { return SerializationUtils.serialize((Serializable) obj); }
Example 17
Source File: IcebergPigInputFormat.java From iceberg with Apache License 2.0 | 4 votes |
@Override public void write(DataOutput out) throws IOException { byte[] data = SerializationUtils.serialize(this.task); out.writeInt(data.length); out.write(data); }
Example 18
Source File: DefaultExceptionCodec.java From reef with Apache License 2.0 | 4 votes |
@Override public byte[] toBytes(final Throwable throwable) { return SerializationUtils.serialize(throwable); }
Example 19
Source File: DefaultIndexManager.java From onedev with MIT License | 4 votes |
private void indexBlob(IndexWriter writer, Repository repository, SymbolExtractor<Symbol> extractor, ObjectId blobId, String blobPath) throws IOException { Document document = new Document(); document.add(new StoredField(BLOB_INDEX_VERSION.name(), getIndexVersion(extractor))); document.add(new StringField(BLOB_HASH.name(), blobId.name(), Store.NO)); document.add(new StringField(BLOB_PATH.name(), blobPath, Store.NO)); document.add(new BinaryDocValuesField(BLOB_PATH.name(), new BytesRef(blobPath.getBytes(StandardCharsets.UTF_8)))); String blobName = blobPath; if (blobPath.indexOf('/') != -1) blobName = StringUtils.substringAfterLast(blobPath, "/"); document.add(new StringField(BLOB_NAME.name(), blobName.toLowerCase(), Store.NO)); ObjectLoader objectLoader = repository.open(blobId); if (objectLoader.getSize() <= MAX_INDEXABLE_SIZE) { byte[] bytes = objectLoader.getCachedBytes(); String content = ContentDetector.convertToText(bytes, blobName); if (content != null) { document.add(new TextField(BLOB_TEXT.name(), content, Store.NO)); if (extractor != null) { List<Symbol> symbols = null; try { symbols = extractor.extract(blobName, StringUtils.removeBOM(content)); } catch (Exception e) { logger.trace("Can not extract symbols from blob (hash:" + blobId.name() + ", path:" + blobPath + ")", e); } if (symbols != null) { for (Symbol symbol: symbols) { String fieldValue = symbol.getName(); if (fieldValue != null && symbol.isSearchable()) { fieldValue = fieldValue.toLowerCase(); String fieldName; if (symbol.isPrimary()) fieldName = BLOB_PRIMARY_SYMBOLS.name(); else fieldName = BLOB_SECONDARY_SYMBOLS.name(); document.add(new StringField(fieldName, fieldValue, Store.NO)); } } byte[] bytesOfSymbols = SerializationUtils.serialize((Serializable) symbols); document.add(new StoredField(BLOB_SYMBOL_LIST.name(), bytesOfSymbols)); } } } else { logger.debug("Ignore content of binary file '{}'.", blobPath); } } else { logger.debug("Ignore content of large file '{}'.", blobPath); } writer.addDocument(document); }
Example 20
Source File: EncryptablePropertiesTest.java From jasypt with Apache License 2.0 | 3 votes |
public void testEncryptablePropertiesSerialization() throws Exception { final BasicTextEncryptor enc01 = new BasicTextEncryptor(); enc01.setPassword("jasypt"); final String msg01 = "Message one"; final String msgEnc01 = "ENC(eZpONwIfFb5muu5Dc8ABsTPu/0OP95p4)"; final String msg02 = "Message two"; final String msgEnc02 = "ENC(LKyQ65EYz3+ekDPpnLjLGyPK07Gt+UZH)"; final EncryptableProperties prop01 = new EncryptableProperties(enc01); prop01.setProperty("p1", msgEnc01); prop01.setProperty("p2", msgEnc02); Assert.assertEquals(prop01.getProperty("p1"), msg01); Assert.assertEquals(prop01.getProperty("p2"), msg02); final byte[] ser01 = SerializationUtils.serialize(prop01); final EncryptableProperties prop02 = (EncryptableProperties) SerializationUtils.deserialize(ser01); Assert.assertEquals(prop02.getProperty("p1"), msg01); Assert.assertEquals(prop02.getProperty("p2"), msg02); Assert.assertNotSame(prop01, prop02); }