public void deserialize(ByteBuffer bb) { stamp = Serialization.readTime(bb); int __joint_names_len = bb.getInt(); joint_names = new java.util.ArrayList<java.lang.String>(__joint_names_len); for (int __i = 0; __i < __joint_names_len; __i++) { joint_names.add(Serialization.readString(bb)); } int __frame_ids_len = bb.getInt(); frame_ids = new java.util.ArrayList<java.lang.String>(__frame_ids_len); for (int __i = 0; __i < __frame_ids_len; __i++) { frame_ids.add(Serialization.readString(bb)); } int __child_frame_ids_len = bb.getInt(); child_frame_ids = new java.util.ArrayList<java.lang.String>(__child_frame_ids_len); for (int __i = 0; __i < __child_frame_ids_len; __i++) { child_frame_ids.add(Serialization.readString(bb)); } int __poses_len = bb.getInt(); poses = new java.util.ArrayList<ros.pkg.geometry_msgs.msg.Pose>(__poses_len); for (int __i = 0; __i < __poses_len; __i++) { ros.pkg.geometry_msgs.msg.Pose __tmp = new ros.pkg.geometry_msgs.msg.Pose(); __tmp.deserialize(bb); poses.add(__tmp); ; } }
@Test public void demonstrateTheProgrammaticAPI() { // #programmatic ActorSystem system = ActorSystem.create("example"); // Get the Serialization Extension Serialization serialization = SerializationExtension.get(system); // Have something to serialize String original = "woohoo"; // Find the Serializer for it Serializer serializer = serialization.findSerializerFor(original); // Turn it into bytes byte[] bytes = serializer.toBinary(original); // Turn it back into an object, // the nulls are for the class manifest and for the classloader String back = (String) serializer.fromBinary(bytes); // Voilá! assertEquals(original, back); // #programmatic system.shutdown(); }
/** * Create Fast Track Package. * * @param packageId The id of the package to start FastTrack * @param signers The signers to get the signing url * @return The signing url */ public String startFastTrack(PackageId packageId, List<FastTrackSigner> signers) { String token = getFastTrackToken(packageId, true); String path = template.urlFor(UrlTemplate.START_FAST_TRACK_PATH).replace("{token}", token).build(); List<FastTrackRole> roles = new ArrayList<FastTrackRole>(); for (FastTrackSigner signer : signers) { FastTrackRole role = FastTrackRoleBuilder.newRoleWithId(signer.getId()) .withName(signer.getId()) .withSigner(signer) .build(); roles.add(role); } String json = Serialization.toJson(roles); try { String response = client.post(path, json); SigningUrl signingUrl = Serialization.fromJson(response, SigningUrl.class); return signingUrl.getUrl(); } catch (RequestException e) { throw new EslException("Could not start fast track.", e); } catch (Exception e) { throw new EslException("Could not start fast track." + " Exception: " + e.getMessage()); } }
public Object readObject(Connection connection) throws IOException { SocketChannel socketChannel = this.socketChannel; if (socketChannel == null) throw new SocketException("Connection is closed."); if (currentObjectLength == 0) { // Read the length of the next object from the socket. int lengthLength = serialization.getLengthLength(); if (readBuffer.remaining() < lengthLength) { readBuffer.compact(); int bytesRead = socketChannel.read(readBuffer); readBuffer.flip(); if (bytesRead == -1) throw new SocketException("Connection is closed."); lastReadTime = System.currentTimeMillis(); if (readBuffer.remaining() < lengthLength) return null; } currentObjectLength = serialization.readLength(readBuffer); if (currentObjectLength <= 0) throw new KryoNetException("Invalid object length: " + currentObjectLength); if (currentObjectLength > readBuffer.capacity()) throw new KryoNetException( "Unable to read object larger than read buffer: " + currentObjectLength); } int length = currentObjectLength; if (readBuffer.remaining() < length) { // Fill the tcpInputStream. readBuffer.compact(); int bytesRead = socketChannel.read(readBuffer); readBuffer.flip(); if (bytesRead == -1) throw new SocketException("Connection is closed."); lastReadTime = System.currentTimeMillis(); if (readBuffer.remaining() < length) return null; } currentObjectLength = 0; int startPosition = readBuffer.position(); int oldLimit = readBuffer.limit(); readBuffer.limit(startPosition + length); Object object; try { object = serialization.read(connection, readBuffer); } catch (Exception ex) { throw new KryoNetException("Error during deserialization.", ex); } readBuffer.limit(oldLimit); if (readBuffer.position() - startPosition != length) throw new KryoNetException( "Incorrect number of bytes (" + (startPosition + length - readBuffer.position()) + " remaining) used to deserialize object: " + object); return object; }
@SuppressWarnings("unchecked") public <T> Serialization<T> getSerialization(Class<T> c) { for (Serialization serialization : serializations) { if (serialization.accept(c)) { return (Serialization<T>) serialization; } } return null; }
public void deserialize(ByteBuffer bb) { workspace_parameters.deserialize(bb); start_state.deserialize(bb); goal_constraints.deserialize(bb); path_constraints.deserialize(bb); planner_id = Serialization.readString(bb); group_name = Serialization.readString(bb); num_planning_attempts = bb.getInt(); allowed_planning_time = Serialization.readDuration(bb); expected_path_duration = Serialization.readDuration(bb); expected_path_dt = Serialization.readDuration(bb); }
public void serialize(ByteBuffer bb, int seq) { workspace_parameters.serialize(bb, seq); start_state.serialize(bb, seq); goal_constraints.serialize(bb, seq); path_constraints.serialize(bb, seq); Serialization.writeString(bb, planner_id); Serialization.writeString(bb, group_name); bb.putInt(num_planning_attempts); Serialization.writeDuration(bb, allowed_planning_time); Serialization.writeDuration(bb, expected_path_duration); Serialization.writeDuration(bb, expected_path_dt); }
/** * Creates a package with roles. * * @param aPackage * @return PackageId * @throws com.silanis.esl.sdk.EslException */ public PackageId createPackage(Package aPackage) throws EslException { String path = template.urlFor(UrlTemplate.PACKAGE_PATH).build(); String packageJson = Serialization.toJson(aPackage); try { String response = client.post(path, packageJson); return Serialization.fromJson(response, PackageId.class); } catch (RequestException e) { throw new EslServerException("Could not create a new package", e); } catch (Exception e) { throw new EslException("Could not create a new package", e); } }
/** * Creates a package and uploads the documents in one step * * @param aPackage * @param documents * @return * @throws EslException */ public PackageId createPackageOneStep( Package aPackage, Collection<com.silanis.esl.sdk.Document> documents) throws EslException { String path = template.urlFor(UrlTemplate.PACKAGE_PATH).build(); String packageJson = Serialization.toJson(aPackage); try { String response = client.postMultipartPackage(path, documents, packageJson); return Serialization.fromJson(response, PackageId.class); } catch (RequestException e) { throw new EslServerException("Could not create a new package in one-step", e); } catch (Exception e) { throw new EslException("Could not create a new package in one-step", e); } }
/** * Get the document's metadata from the package. * * @param documentPackage The DocumentPackage we want to get document from. * @param documentId Id of document to get. * @return the document's metadata */ public com.silanis.esl.sdk.Document getDocumentMetadata( DocumentPackage documentPackage, String documentId) { String path = template .urlFor(UrlTemplate.DOCUMENT_ID_PATH) .replace("{packageId}", documentPackage.getId().getId()) .replace("{documentId}", documentId) .build(); try { String response = client.get(path); Document apilDocument = Serialization.fromJson(response, Document.class); // Wipe out the members not related to the metadata apilDocument.setApprovals(new ArrayList<Approval>()); apilDocument.setFields(new ArrayList<Field>()); apilDocument.setPages(new ArrayList<com.silanis.esl.api.model.Page>()); return new DocumentConverter( apilDocument, new DocumentPackageConverter(documentPackage).toAPIPackage()) .toSDKDocument(); } catch (RequestException e) { throw new EslServerException("Could not get the document's metadata.", e); } catch (Exception e) { throw new EslException( "Could not get the document's metadata." + " Exception: " + e.getMessage()); } }
@Test public void serializeActorRefs() { final ActorSystem theActorSystem = ActorSystem.create("whatever"); final ActorRef theActorRef = theActorSystem.deadLetters(); // Of course this should be you // #actorref-serializer // Serialize // (beneath toBinary) final Address transportAddress = Serialization.currentTransportAddress().value(); String identifier; // If there is no transportAddress, // it means that either this Serializer isn't called // within a piece of code that sets it, // so either you need to supply your own, // or simply use the local path. if (transportAddress == null) identifier = theActorRef.path().toString(); else identifier = theActorRef.path().toStringWithAddress(transportAddress); // Then just serialize the identifier however you like // Deserialize // (beneath fromBinary) final ActorRef deserializedActorRef = theActorSystem.actorFor(identifier); // Then just use the ActorRef // #actorref-serializer theActorSystem.shutdown(); }
/** * @serialData key comparator, value comparator, number of distinct keys, and then for each * distinct key: the key, number of values for that key, and key values */ @GwtIncompatible("java.io.ObjectOutputStream") private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeObject(keyComparator()); stream.writeObject(valueComparator()); Serialization.writeMultimap(this, stream); }
/** This method is thread safe. */ public int send(Connection connection, Object object) throws IOException { SocketChannel socketChannel = this.socketChannel; if (socketChannel == null) throw new SocketException("Connection is closed."); synchronized (writeLock) { // Leave room for length. int start = writeBuffer.position(); int lengthLength = serialization.getLengthLength(); writeBuffer.position(writeBuffer.position() + lengthLength); // Write data. try { serialization.write(connection, writeBuffer, object); } catch (KryoNetException ex) { throw new KryoNetException( "Error serializing object of type: " + object.getClass().getName(), ex); } int end = writeBuffer.position(); // Write data length. writeBuffer.position(start); serialization.writeLength(writeBuffer, end - lengthLength - start); writeBuffer.position(end); // Write to socket if no data was queued. if (start == 0 && !writeToSocket()) { // A partial write, set OP_WRITE to be notified when more writing can occur. selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE); } else { // Full write, wake up selector so idle event will be fired. selectionKey.selector().wakeup(); } if (DEBUG || TRACE) { float percentage = writeBuffer.position() / (float) writeBuffer.capacity(); if (DEBUG && percentage > 0.75f) debug( "kryonet", connection + " TCP write buffer is approaching capacity: " + percentage + "%"); else if (TRACE && percentage > 0.25f) trace("kryonet", connection + " TCP write buffer utilization: " + percentage + "%"); } lastWriteTime = System.currentTimeMillis(); return end - start; } }
public com.silanis.esl.sdk.Document uploadApiDocument( String packageId, String fileName, byte[] fileBytes, Document document) { String path = template.urlFor(UrlTemplate.DOCUMENT_PATH).replace("{packageId}", packageId).build(); String documentJson = Serialization.toJson(document); try { String response = client.postMultipartFile(path, fileName, fileBytes, documentJson); com.silanis.esl.api.model.Document uploadedDocument = Serialization.fromJson(response, com.silanis.esl.api.model.Document.class); return new DocumentConverter(uploadedDocument, getApiPackage(packageId)).toSDKDocument(); } catch (RequestException e) { throw new EslServerException("Could not upload document to package.", e); } catch (Exception e) { throw new EslException("Could not upload document to package.", e); } }
@GwtIncompatible("java.io.ObjectInputStream") @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyComparator = checkNotNull((Comparator<? super K>) stream.readObject()); valueComparator = checkNotNull((Comparator<? super V>) stream.readObject()); setMap(new TreeMap<K, Collection<V>>(keyComparator)); Serialization.populateMultimap(this, stream); }
public void deserialize(ByteBuffer bb) { header.deserialize(bb); link_name = Serialization.readString(bb); type = bb.getInt(); orientation.deserialize(bb); absolute_roll_tolerance = bb.getDouble(); absolute_pitch_tolerance = bb.getDouble(); absolute_yaw_tolerance = bb.getDouble(); weight = bb.getDouble(); }
public void serialize(ByteBuffer bb, int seq) { header.serialize(bb, seq); Serialization.writeString(bb, link_name); bb.putInt(type); orientation.serialize(bb, seq); bb.putDouble(absolute_roll_tolerance); bb.putDouble(absolute_pitch_tolerance); bb.putDouble(absolute_yaw_tolerance); bb.putDouble(weight); }
public void serialize(ByteBuffer bb, int seq) { Serialization.writeTime(bb, stamp); bb.putInt(joint_names.size()); for (java.lang.String val : joint_names) { Serialization.writeString(bb, val); } bb.putInt(frame_ids.size()); for (java.lang.String val : frame_ids) { Serialization.writeString(bb, val); } bb.putInt(child_frame_ids.size()); for (java.lang.String val : child_frame_ids) { Serialization.writeString(bb, val); } bb.putInt(poses.size()); for (ros.pkg.geometry_msgs.msg.Pose val : poses) { val.serialize(bb, seq); } }
@Test public void whenThereIsAFormatGivenShouldUseCorrectSerializer() { when(formatResolver.getAcceptFormat()).thenReturn("xml"); when(serialization.accepts("xml")).thenReturn(true); Object object = new Object(); representation.from(object); verify(serialization).from(object); }
@Test public void whenSerializationDontAcceptsFormatItShouldntBeUsed() { when(formatResolver.getAcceptFormat()).thenReturn("xml"); when(serialization.accepts("xml")).thenReturn(false); Object object = new Object(); representation.from(object); verify(serialization, never()).from(object); }
/** * Adds a signer to the specified package * * @param packageId The id of the package in which the signer will be added * @param signer The signer to be added * @return The role id of the signer */ public String addSigner(PackageId packageId, com.silanis.esl.sdk.Signer signer) { Role apiPayload = new SignerConverter(signer).toAPIRole(UUID.randomUUID().toString().replace("-", "")); String path = template .urlFor(UrlTemplate.ADD_SIGNER_PATH) .replace("{packageId}", packageId.getId()) .build(); try { String json = Serialization.toJson(apiPayload); String response = client.post(path, json); Role apiRole = Serialization.fromJson(response, Role.class); return apiRole.getId(); } catch (RequestException e) { throw new EslServerException("Could not add signer.", e); } catch (Exception e) { throw new EslException("Could not add signer." + " Exception: " + e.getMessage()); } }
/** * Create a new package based on an existing template. * * @param packageId * @param aPackage * @return PackageId */ public PackageId createPackageFromTemplate(PackageId packageId, Package aPackage) { String path = template .urlFor(UrlTemplate.TEMPLATE_PATH) .replace("{packageId}", packageId.getId()) .build(); List<Role> roles = aPackage.getRoles(); aPackage.setRoles(Collections.<Role>emptyList()); String packageJson = Serialization.toJson(aPackage); PackageId newPackageId = null; try { String response = client.post(path, packageJson); newPackageId = Serialization.fromJson(response, PackageId.class); } catch (RequestException e) { throw new EslServerException("Could not create a new package", e); } catch (Exception e) { throw new EslException("Could not create a new package", e); } Package createdPackage = getApiPackage(newPackageId.getId()); for (Role role : roles) { String roleUid = findRoleUidByName(createdPackage.getRoles(), role.getName()); if (roleUid == null) { continue; } role.setId(roleUid); updateRole(newPackageId, role); } return newPackageId; }
/** * Gets the package. * * @param packageId * @return Package * @throws EslException */ public Package getApiPackage(String packageId) throws EslException { String path = template.urlFor(UrlTemplate.PACKAGE_ID_PATH).replace("{packageId}", packageId).build(); String stringResponse; try { stringResponse = client.get(path); } catch (RequestException e) { throw new EslServerException("Could not get package.", e); } catch (Exception e) { throw new EslException("Could not get package.", e); } return Serialization.fromJson(stringResponse, Package.class); }
/** * Gets the roles for a package. * * @param packageId * @return A list of the roles in the package * @throws EslException */ public List<Role> getRoles(PackageId packageId) throws EslException { String path = template.urlFor(UrlTemplate.ROLE_PATH).replace("{packageId}", packageId.getId()).build(); String stringResponse; try { stringResponse = client.get(path); } catch (RequestException e) { throw new EslServerException( "Could not retrieve list of roles for package with id " + packageId.getId(), e); } catch (Exception e) { throw new EslException( "Could not retrieve list of roles for package with id " + packageId.getId(), e); } return Serialization.fromJson(stringResponse, RoleList.class).getResults(); }
/** * Adds a role to the package. * * @param packageId * @param role * @return The role added * @throws EslException */ public Role addRole(PackageId packageId, Role role) throws EslException { String path = template.urlFor(UrlTemplate.ROLE_PATH).replace("{packageId}", packageId.getId()).build(); String roleJson = JacksonUtil.serializeDirty(role); String stringResponse; try { stringResponse = client.post(path, roleJson); } catch (RequestException e) { throw new EslServerException("Could not add role.", e); } catch (Exception e) { throw new EslException("Could not add role.", e); } return Serialization.fromJson(stringResponse, Role.class); }
private String getFastTrackUrl(PackageId packageId, Boolean signing) { String path = template .urlFor(UrlTemplate.FAST_TRACK_URL_PATH) .replace("{packageId}", packageId.getId()) .replace("{signing}", signing.toString()) .build(); try { String json = client.get(path); SigningUrl signingUrl = Serialization.fromJson(json, SigningUrl.class); return signingUrl.getUrl(); } catch (RequestException e) { throw new EslException("Could not get a fastTrack url.", e); } catch (Exception e) { throw new EslException("Could not get a fastTrack url." + " Exception: " + e.getMessage()); } }
/** * Get thank you dialog content. * * @param packageId The id of the package to get thank you dialog content. * @return thank you dialog content */ public String getThankYouDialogContent(PackageId packageId) { String path = template .urlFor(UrlTemplate.THANK_YOU_DIALOG_PATH) .replace("{packageId}", packageId.getId()) .build(); try { String json = client.get(path); Properties thankYouDialogContent = Serialization.fromJson(json, Properties.class); return thankYouDialogContent.getProperty("body"); } catch (RequestException e) { throw new EslException("Could not get thank you dialog content.", e); } catch (Exception e) { throw new EslException( "Could not get thank you dialog content." + " Exception: " + e.getMessage()); } }
/** * Upload documents with external content to the package. * * @param packageId */ public void addDocumentWithExternalContent( String packageId, List<com.silanis.esl.sdk.Document> providerDocuments) { String path = template.urlFor(UrlTemplate.DOCUMENT_PATH).replace("{packageId}", packageId).build(); List<Document> apiDocuments = new ArrayList<Document>(); for (com.silanis.esl.sdk.Document document : providerDocuments) { apiDocuments.add(new DocumentConverter(document).toAPIDocumentMetadata()); } try { String json = Serialization.toJson(apiDocuments); client.post(path, json); } catch (RequestException e) { throw new EslServerException("Could not upload the documents.", e); } catch (Exception e) { throw new EslException("Could not upload the documents." + " Exception: " + e.getMessage()); } }
private static EventQueueBackingStore upgrade( File checkpointFile, int capacity, String name, File backupCheckpointDir, boolean shouldBackup, boolean compressBackup) throws Exception { LOG.info("Attempting upgrade of " + checkpointFile + " for " + name); EventQueueBackingStoreFileV2 backingStoreV2 = new EventQueueBackingStoreFileV2(checkpointFile, capacity, name); String backupName = checkpointFile.getName() + "-backup-" + System.currentTimeMillis(); Files.copy(checkpointFile, new File(checkpointFile.getParentFile(), backupName)); File metaDataFile = Serialization.getMetaDataFile(checkpointFile); EventQueueBackingStoreFileV3.upgrade(backingStoreV2, checkpointFile, metaDataFile); return new EventQueueBackingStoreFileV3( checkpointFile, capacity, name, backupCheckpointDir, shouldBackup, compressBackup); }
/** * Get package support configuration. * * @param packageId The id of the package to get package support configuration. * @return package support configuration */ public SupportConfiguration getConfig(PackageId packageId) { String path = template .urlFor(UrlTemplate.PACKAGE_INFORMATION_CONFIG_PATH) .replace("{packageId}", packageId.getId()) .build(); try { String json = client.get(path); com.silanis.esl.api.model.SupportConfiguration apiSupportConfiguration = Serialization.fromJson(json, com.silanis.esl.api.model.SupportConfiguration.class); return new SupportConfigurationConverter(apiSupportConfiguration).toSDKSupportConfiguration(); } catch (RequestException e) { throw new EslException("Could not get support configuration.", e); } catch (Exception e) { throw new EslException( "Could not get support configuration." + " Exception: " + e.getMessage()); } }