/** * Load parcel from specified path. * * @param fileName * * @return loaded Parcel. */ public static Parcel loadParcel(String fileName) throws IOException { Parcel parcel = null; File pathFile = new File(fileName); if (pathFile.exists()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); parcel = Parcel.unpack(data); } else { addError(Errors.NOT_FOUND.name(), fileName, "Path " + fileName + " does not exist"); } return parcel; }
@Override public Parcel getParcel(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { try { // URL url = new URL("http://localhost:8080/contracts/" + itemId.toBase64String()); URL url = new URL(nodeInfo.publicUrlString() + "/parcels/" + itemId.toBase64String()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestProperty("Connection", "close"); connection.setRequestMethod("GET"); if (200 != connection.getResponseCode()) return null; byte[] data = Do.read(connection.getInputStream()); Parcel parcel = Parcel.unpack(data); // tp.trace(); // Contract c = Contract.fromPackedTransaction(data); return parcel; } catch (Exception e) { report(getLabel(), "download failure. from: " + nodeInfo.getNumber() + " by: " + myInfo.getNumber() +" reason: " + e); return null; } }
private Binder approveParcel(Binder params, Session session) throws IOException, Quantiser.QuantiserException { checkNode(session); try { // System.out.println("Request to approve parcel, package size: " + params.getBinaryOrThrow("packedItem").length); return Binder.of( "result", node.registerParcel(Parcel.unpack(params.getBinaryOrThrow("packedItem"))) ); } catch (Exception e) { System.out.println("approveParcel ERROR: " + e.getMessage()); return Binder.of( "itemResult", itemResultOfError(Errors.COMMAND_FAILED,"approveParcel", e.getMessage())); } }
@Override synchronized public Parcel getParcel(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { synchronized (mutex) { Node node = nodes.get(nodeInfo); Parcel parcel = node.getParcel(itemId); byte[] array = parcel.pack(); //unpack Parcel des_parcel = null; try { des_parcel = Parcel.unpack(array); } catch (Exception e) { System.out.println("error parcel "); e.printStackTrace(); } return des_parcel; // return parcel; } }
Instant end = Instant.now().plusMillis(millisToWait); try { Parcel parcel = Parcel.unpack(packed); Node.ParcelProcessingState pState = getParcelProcessingState(parcel.getId()); int interval = 1000;
@Test public void packUnpack() throws Exception { //pack byte[] array = parcel.pack(); byte[] array1 = parcelFromFile.pack(); //unpack des_parcel = Parcel.unpack(array); des_parcelFromFile = Parcel.unpack(array1); parcelAssertions(parcel, des_parcel); parcelAssertions(parcelFromFile, des_parcelFromFile); assertEquals(1, des_parcel.getPayload().getSubItems().size()); assertEquals(1, des_parcel.getPayload().getContract().getNew().size()); } }
payingParcel = Parcel.unpack(payingParcel.pack());