List of usage examples for org.apache.commons.lang SerializationUtils deserialize
public static Object deserialize(byte[] objectData)
Deserializes a single Object
from an array of bytes.
From source file:com.portfolioeffect.quant.client.ClientConnection.java
public MethodResult getAllSymbolsList() throws Exception { Message responseMsg;// w ww. j a va 2 s. c om Message msg = ClientRequestMessageFactory.createTransactionalPortfolioComputeRequest(getTemplateRegistry(), "ALL_SYMBOLS", "", "", getOutboundMsgSequenceNumber(), System.currentTimeMillis()); responseMsg = sendAndAwaitResponse(msg, USER_LAYER_TIMEOUT_SECONDS_ESTIMATE); TransmitDataRequest response = ServerResponseMessageParser.parseTransmitDataRequest(responseMsg); MethodResult result = new MethodResult(); if (response.getMsgType().contains("OK")) { byte data[] = response.getDataFloatByte(); data = Snappy.uncompress(data, 0, data.length); Map<String, String[]> map = (Map<String, String[]>) SerializationUtils.deserialize(data); ArrayCache id = new ArrayCache(map.get("id")); ArrayCache description = new ArrayCache(map.get("description")); ArrayCache exchange = new ArrayCache(map.get("exchange")); result.setData("id", id); result.setData("description", description); result.setData("exchange", exchange); } else { throw new Exception(response.getMsgBody()); } return result; }
From source file:info.raack.appliancelabeler.data.JDBCDatabase.java
@Override public AlgorithmResult getAlgorithmResultForMonitorAndAlgorithm(final EnergyMonitor monitor, final ApplianceEnergyConsumptionDetectionAlgorithm algorithm) { try {// www . j a v a 2s. c o m return jdbcTemplate.queryForObject( "select * from algorithm_models where energy_monitor_id = ? and detection_algorithm = ?", new Object[] { monitor.getId(), algorithm.getId() }, new RowMapper<AlgorithmResult>() { @Override public AlgorithmResult mapRow(ResultSet rs, int arg1) throws SQLException { byte[] modelResult = getModelResultFromDisk(monitor.getId()); Serializable result = null; try { Object tokenObject = SerializationUtils.deserialize(modelResult); result = (Serializable) tokenObject; } catch (Exception e) { throw new RuntimeException("Could not deserialize blob into algorithm result", e); } return new AlgorithmResult(monitor, algorithm, result); } private byte[] getModelResultFromDisk(int id) { try { return FileUtils.readFileToByteArray(getResultFile(id)); } catch (IOException e) { logger.warn("Could not read model from disk", e); return null; } } }); } catch (EmptyResultDataAccessException e) { // no algorithm result return null; } }
From source file:com.ephesoft.dcma.da.common.ExecuteUpdatePatch.java
private Map<String, List<Dependency>> readPluginDependenciesSerializeFile() { FileInputStream fileInputStream = null; Map<String, List<Dependency>> newPluginNameVsDependencyMap = null; File serializedFile = null;/*w w w .j ava2 s . c o m*/ try { String dependenciesConfigFilePath = dbPatchFolderLocation + File.separator + DataAccessConstant.DEPENDENCY_UPDATE + SERIALIZATION_EXT; serializedFile = new File(dependenciesConfigFilePath); fileInputStream = new FileInputStream(serializedFile); newPluginNameVsDependencyMap = (Map<String, List<Dependency>>) SerializationUtils .deserialize(fileInputStream); updateFile(serializedFile, dependenciesConfigFilePath); } catch (IOException e) { LOG.error(DataAccessConstant.ERROR_DURING_READING_THE_SERIALIZED_FILE); } catch (Exception e) { LOG.error(DataAccessConstant.ERROR_DURING_DE_SERIALIZING_THE_PROPERTIES_FOR_DATABASE_UPGRADE, e); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (Exception e) { if (serializedFile != null) { LOG.error(DataAccessConstant.PROBLEM_CLOSING_STREAM_FOR_FILE + serializedFile.getName()); } } } return newPluginNameVsDependencyMap; }
From source file:com.ephesoft.dcma.gwt.admin.bm.server.BatchClassManagementServiceImpl.java
/** * API to match the work flow content for equality with same module(s) and their sequence and also same plugin(s) and sequence. * // w ww .j av a 2 s. c om * @param userOptions ImportBatchClassUserOptionDTO * @param userInputWorkflowName String * @return Map<String, Boolean> */ @Override public Map<String, Boolean> isWorkflowContentEqual(ImportBatchClassUserOptionDTO userOptions, String userInputWorkflowName) { ImportBatchService imService = this.getSingleBeanOfType(ImportBatchService.class); DeploymentService deployService = this.getSingleBeanOfType(DeploymentService.class); Map<String, Boolean> results = new HashMap<String, Boolean>(); boolean isEqual = false; boolean isDeployed = deployService.isDeployed(userInputWorkflowName); InputStream serializableFileStream = null; String serializableFilePath = FileUtils.getFileNameOfTypeFromFolder(userOptions.getZipFileName(), SERIALIZATION_EXT); BatchClass importBatchClass = null; try { serializableFileStream = new FileInputStream(serializableFilePath); try { // Import Into Database from the serialized file importBatchClass = (BatchClass) SerializationUtils.deserialize(serializableFileStream); } finally { try { if (serializableFileStream != null) { serializableFileStream.close(); } } catch (IOException ioe) { LOGGER.info("Error while closing file input stream.File name:" + serializableFilePath, ioe); } } } catch (Exception e) { LOGGER.error("Error while importing" + e, e); } if (importBatchClass != null) { isEqual = imService.isImportWorkflowEqualDeployedWorkflow(importBatchClass, userInputWorkflowName); } results.put("isEqual", isEqual); results.put("isDepoyed", isDeployed); return results; }
From source file:com.ephesoft.dcma.gwt.admin.bm.server.BatchClassManagementServiceImpl.java
/** * API to get import BatchClass UI Configuration given the workflow Name and zip Source Path. * //from w w w .j av a 2 s . c o m * @param workflowName {@link String} * @param zipSourcePath {@link String} * @return {@link ImportBatchClassSuperConfig} */ @Override public ImportBatchClassSuperConfig getImportBatchClassUIConfig(String workflowName, String zipSourcePath) { ImportBatchClassSuperConfig config = new ImportBatchClassSuperConfig(); BatchClassService batchClassService = this.getSingleBeanOfType(BatchClassService.class); BatchSchemaService batchSchemaService = this.getSingleBeanOfType(BatchSchemaService.class); List<String> uncFolders = batchClassService.getAllUNCList(true); BatchClass dbBatchClass; Set<String> batchClassesByUserRoles = getAllBatchClassByUserRoles(); for (String uncFolder : uncFolders) { dbBatchClass = batchClassService.getBatchClassbyUncFolder(uncFolder); if (dbBatchClass != null && dbBatchClass.getIdentifier() != null && batchClassesByUserRoles.contains(dbBatchClass.getIdentifier())) { config.addUncFolderConfig(dbBatchClass.getIdentifier(), dbBatchClass.getName(), uncFolder); } } InputStream serializableFileStream = null; String serializableFilePath = FileUtils.getFileNameOfTypeFromFolder(zipSourcePath, SERIALIZATION_EXT); try { serializableFileStream = new FileInputStream(serializableFilePath); BatchClass importBatchClass = null; try { // Import Into Database from the serialized file importBatchClass = (BatchClass) SerializationUtils.deserialize(serializableFileStream); } finally { try { if (serializableFileStream != null) { serializableFileStream.close(); } } catch (IOException ioe) { LOGGER.info("Error while closing file input stream.File name:" + serializableFilePath, ioe); } } if (importBatchClass != null) { Node rootNode = config.getUiConfigRoot(); BatchClassUtil.populateUICOnfig(importBatchClass, rootNode, batchClassService, workflowName, zipSourcePath, batchSchemaService); } } catch (Exception e) { LOGGER.error("Error while importing" + e, e); config = null; } return config; }
From source file:com.ephesoft.gxt.systemconfig.server.SystemConfigServiceImpl.java
/** * Imports new regex groups, which are not already present in database. Returns Map containing all imported file names with * corresponding value , depending on the success of import. * /*from w w w . j av a 2 s.co m*/ * @param importPoolDTOs {@link ImportRegexPoolDTO}- list of imported regex pool DTO. * @return Map<String, Boolean> */ @Override public Map<String, Boolean> importRegexGroups(List<ImportPoolDTO> importPoolDTOs) { Map<String, Boolean> resultMap = new HashMap<String, Boolean>(); if (!CollectionUtil.isEmpty(importPoolDTOs)) { for (ImportPoolDTO importRegexPoolDTO : importPoolDTOs) { if (null != importRegexPoolDTO) { String serializableFilePath = FileUtils.getFileNameOfTypeFromFolder( importRegexPoolDTO.getZipFileLocation(), SERIALIZATION_EXT); InputStream serializableFileStream = null; try { if (!StringUtil.isNullOrEmpty(serializableFilePath)) { serializableFileStream = new FileInputStream(serializableFilePath); Object deserializedObject = SerializationUtils.deserialize(serializableFileStream); if (deserializedObject instanceof List<?>) { boolean instanceOfRegexGroup = true; List<?> deserializedList = (List<?>) deserializedObject; for (Object object : deserializedList) { if (!(object instanceof RegexGroup)) { instanceOfRegexGroup = false; break; } } if (instanceOfRegexGroup) { // List of imported regex groups @SuppressWarnings("unchecked") final List<RegexGroup> importRegexGroupList = (List<RegexGroup>) deserializedObject; insertRegexGroups(importRegexGroupList); resultMap.put(importRegexPoolDTO.getZipFileName(), true); } else { resultMap.put(importRegexPoolDTO.getZipFileName(), false); } } else { resultMap.put(importRegexPoolDTO.getZipFileName(), false); } } else { resultMap.put(importRegexPoolDTO.getZipFileName(), false); } } catch (final FileNotFoundException fileNotFoundException) { LOGGER.error(fileNotFoundException, "Error while importing regex groups: ", fileNotFoundException.getMessage()); resultMap.put(importRegexPoolDTO.getZipFileName(), false); } catch (final DataAccessException dataAccessException) { LOGGER.error(dataAccessException, "Error while importing regex groups: ", dataAccessException.getMessage()); resultMap.put(importRegexPoolDTO.getZipFileName(), false); } } } } return resultMap; }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java
/** * Gets the Batch Description from the SER file if available. * // ww w. j a v a 2s. c o m * @param uncSubfolder {@link String} * @return batchDescription {@link String} */ private String getBatchDescriptionFromSERFile(final String uncSubfolder, final String batchName) { String batchDescription = null; FileInputStream fileInputStream = null; if (!EphesoftStringUtil.isNullOrEmpty(uncSubfolder)) { final String serializedFilePath = EphesoftStringUtil.concatenate(uncSubfolder, File.separator, BID_SER_FILE_NAME, SERIALIZATION_EXT); final File serializedFile = new File(serializedFilePath); if (serializedFile.exists()) { try { fileInputStream = new FileInputStream(serializedFile); batchDescription = SerializationUtils.deserialize(fileInputStream).toString(); serializedFile.delete(); } catch (final IOException ioException) { log.info(EphesoftStringUtil.concatenate("Error during reading the serialized file. ", ioException.getMessage())); } catch (final SerializationException serException) { log.error("Error during de-serializing the Batch Description: ", serException.getMessage()); } catch (final IllegalArgumentException illegalArgumentException) { log.error("Error during parsing File Input Stream : ", illegalArgumentException.getMessage()); } catch (final SecurityException securityException) { log.info("Unable to delete serialized file : ", securityException.getMessage()); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (final IOException ioException) { if (serializedFile != null) { log.error(EphesoftStringUtil.concatenate("Problem closing stream for file : ", serializedFile.getName(), ioException.getMessage())); } } } } else { log.info("Serialised file not found in UNC sub folder. Setting Batch Name as Batch Description."); batchDescription = batchName; } } return batchDescription; }
From source file:ch.zhaw.ficore.p2abc.services.verification.VerificationService.java
/** * @fiware-rest-path /getSettings//*from w ww .j ava 2s . com*/ * @fiware-rest-method GET * * @fiware-rest-description Returns the settings of the service as obtained * from an issuance service. Settings includes * issuer parameters, credential specifications and * the system parameters. This method may thus be * used to retrieve all credential specifications * stored at the user service and their * corresponding issuer parameters. The return type * of this method is <tt>Settings</tt>. * * The user service is capable of downloading * settings from an issuer (or from anything that * provides settings). To download settings use * <tt>/loadSettings?url=...</tt> ( * {@link #loadSettings(String)}). * * @fiware-rest-response 200 OK (application/xml) * @fiware-rest-response 500 ERROR * @fiware-rest-return-type Settings * @return Response */ @GET() @Path("/getSettings/") public Response getSettings() { /* [TEST EXISTS] */ log.entry(); try { VerificationHelper instance = VerificationHelper.getInstance(); Settings settings = new Settings(); List<IssuerParameters> issuerParams = new ArrayList<IssuerParameters>(); for (URI uri : instance.keyStorage.listUris()) { Object obj = SerializationUtils.deserialize(instance.keyStorage.getValue(uri)); if (obj instanceof IssuerParameters) { IssuerParameters ip = (IssuerParameters) obj; SystemParameters serializeSp = (ip.getSystemParameters()); ip.setSystemParameters(serializeSp); issuerParams.add(ip); } } List<CredentialSpecification> credSpecs = new ArrayList<CredentialSpecification>(); for (URI uri : instance.keyStorage.listUris()) { Object obj = SerializationUtils.deserialize(instance.keyStorage.getValue(uri)); if (obj instanceof CredentialSpecification) { credSpecs.add((CredentialSpecification) obj); } } settings.credentialSpecifications = credSpecs; settings.issuerParametersList = issuerParams; try { settings.systemParameters = /* SystemParametersUtil.serialize */(instance.keyManager .getSystemParameters()); } catch (Exception e) { log.catching(e); } return log.exit(Response.ok(settings, MediaType.APPLICATION_XML).build()); } catch (Exception e) { log.catching(e); return log.exit(Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity(ExceptionDumper.dumpExceptionStr(e, log))).build(); } }
From source file:org.apache.camel.component.kafka.KafkaComponentUtil.java
/** * Utility method to serialize the whole exchange. * * @param body// w ww . j ava 2 s .c o m * @return */ public static Object deserializeBody(final byte[] body) { return SerializationUtils.deserialize(body); }
From source file:org.apache.camel.component.kafka.KafkaComponentUtil.java
/** * Utility method to create exchange from incoming data * * @param incomingData/*from w ww. j a v a2s .c om*/ * @param configuration */ protected static Exchange constructExchange(final KafkaEndpoint endpoint, final MessageAndMetadata<byte[], byte[]> incomingData, final KafkaConfiguration configuration) { Exchange exchange = new DefaultExchange(endpoint.getCamelContext(), endpoint.getExchangePattern()); if (configuration.isTransferExchange()) { // transfer exchange? DefaultExchangeHolder exchangeHolder = (DefaultExchangeHolder) SerializationUtils .deserialize(incomingData.message()); DefaultExchangeHolder.unmarshal(exchange, exchangeHolder); } else { final Message message = new DefaultMessage(); message.setBody(deserializeBody(incomingData.message())); exchange.setIn(message); } fillExchangeInMessageWithMetadata(exchange, incomingData); return exchange; }