List of usage examples for org.apache.hadoop.io DataInputByteBuffer reset
public void reset(ByteBuffer... input)
From source file:com.datatorrent.stram.StreamingContainerManagerTest.java
License:Apache License
@Test public void testDeployInfoSerialization() throws Exception { OperatorDeployInfo ndi = new OperatorDeployInfo(); ndi.name = "node1"; ndi.type = OperatorDeployInfo.OperatorType.GENERIC; ndi.id = 1;/*from www .j ava2s . c o m*/ ndi.contextAttributes = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap(); ndi.contextAttributes.put(OperatorContext.SPIN_MILLIS, 100); OperatorDeployInfo.InputDeployInfo input = new OperatorDeployInfo.InputDeployInfo(); input.declaredStreamId = "streamToNode"; input.portName = "inputPortNameOnNode"; input.sourceNodeId = 99; ndi.inputs = new ArrayList<OperatorDeployInfo.InputDeployInfo>(); ndi.inputs.add(input); OperatorDeployInfo.OutputDeployInfo output = new OperatorDeployInfo.OutputDeployInfo(); output.declaredStreamId = "streamFromNode"; output.portName = "outputPortNameOnNode"; ndi.outputs = new ArrayList<OperatorDeployInfo.OutputDeployInfo>(); ndi.outputs.add(output); ContainerHeartbeatResponse scc = new ContainerHeartbeatResponse(); scc.deployRequest = Collections.singletonList(ndi); DataOutputByteBuffer out = new DataOutputByteBuffer(); scc.write(out); DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(out.getData()); ContainerHeartbeatResponse clone = new ContainerHeartbeatResponse(); clone.readFields(in); Assert.assertNotNull(clone.deployRequest); Assert.assertEquals(1, clone.deployRequest.size()); OperatorDeployInfo ndiClone = clone.deployRequest.get(0); Assert.assertEquals("name", ndi.name, ndiClone.name); Assert.assertEquals("type", ndi.type, ndiClone.type); String nodeToString = ndi.toString(); Assert.assertTrue(nodeToString.contains(input.portName)); Assert.assertTrue(nodeToString.contains(output.portName)); Assert.assertEquals("contextAttributes " + ndiClone.contextAttributes, Integer.valueOf(100), ndiClone.contextAttributes.get(OperatorContext.SPIN_MILLIS)); }
From source file:org.apache.asterix.external.parser.test.ADMDataParserTest.java
License:Apache License
@Test public void testWKTParser() { try {// ww w .j a v a 2 s .c o m ARecordType recordType = new ARecordType("POIType", new String[] { "id", "coord" }, new IAType[] { BuiltinType.AINT32, BuiltinType.AGEOMETRY }, false); String wktObject = "{\"id\": 123, \"coord\": \"POINT(3 4)\"}"; InputStream in = new ByteArrayInputStream(wktObject.getBytes()); ADMDataParser parser = new ADMDataParser(recordType, true); parser.setInputStream(in); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); parser.parse(out); out.close(); byte[] serialized = baos.toByteArray(); // Parse to make sure it was correct ByteBuffer bb = ByteBuffer.wrap(serialized); Assert.assertEquals(ATypeTag.SERIALIZED_RECORD_TYPE_TAG, bb.get()); Assert.assertEquals(serialized.length, bb.getInt()); // Total record size including header Assert.assertEquals(2, bb.getInt()); // # of records int offsetOfID = bb.getInt(); int offsetOfGeometry = bb.getInt(); ISerializerDeserializer intDeser = SerializerDeserializerProvider.INSTANCE .getNonTaggedSerializerDeserializer(BuiltinType.AINT32); Assert.assertEquals(offsetOfID, bb.position()); // Serialize the two records DataInputByteBuffer dataIn = new DataInputByteBuffer(); dataIn.reset(bb); Object o = intDeser.deserialize(dataIn); Assert.assertEquals(new AInt32(123), o); ISerializerDeserializer geomDeser = SerializerDeserializerProvider.INSTANCE .getNonTaggedSerializerDeserializer(BuiltinType.AGEOMETRY); Object point = geomDeser.deserialize(dataIn); Assert.assertTrue(point instanceof AGeometry); Assert.assertTrue(((AGeometry) point).getGeometry() instanceof OGCPoint); OGCPoint p = (OGCPoint) ((AGeometry) point).getGeometry(); Assert.assertEquals(3.0, p.X(), 1E-5); Assert.assertEquals(4.0, p.Y(), 1E-5); } catch (IOException e) { e.printStackTrace(); Assert.fail("Error in parsing"); } }
From source file:org.apache.tajo.pullserver.PullServerAuxService.java
License:Apache License
/** * A helper function to deserialize the metadata returned by PullServerAuxService. * @param meta the metadata returned by the PullServerAuxService * @return the port the PullServer Handler is listening on to serve shuffle data. *///from w ww .j a va 2s . com public static int deserializeMetaData(ByteBuffer meta) throws IOException { //TODO this should be returning a class not just an int DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(meta); return in.readInt(); }
From source file:org.apache.tez.auxservices.ShuffleHandler.java
License:Apache License
/** * A helper function to deserialize the metadata returned by ShuffleHandler. * @param meta the metadata returned by the ShuffleHandler * @return the port the Shuffle Handler is listening on to serve shuffle data. *///from w w w . java 2 s. co m public static int deserializeMetaData(ByteBuffer meta) throws IOException { //TODO this should be returning a class not just an int DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(meta); int port = in.readInt(); return port; }
From source file:org.apache.tez.auxservices.ShuffleHandler.java
License:Apache License
static Token<JobTokenIdentifier> deserializeServiceData(ByteBuffer secret) throws IOException { DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(secret); Token<JobTokenIdentifier> jt = new Token<JobTokenIdentifier>(); jt.readFields(in);//from w ww . ja v a2 s .c o m return jt; }
From source file:org.apache.tez.dag.api.DagTypeConverters.java
License:Apache License
public static Credentials convertByteStringToCredentials(ByteString byteString) { if (byteString == null) { return null; }// w w w. j a va 2 s .co m DataInputByteBuffer dib = new DataInputByteBuffer(); dib.reset(byteString.asReadOnlyByteBuffer()); Credentials credentials = new Credentials(); try { credentials.readTokenStorageStream(dib); return credentials; } catch (IOException e) { throw new TezUncheckedException("Failed to deserialize Credentials", e); } }
From source file:org.apache.tez.runtime.library.common.shuffle.ShuffleUtils.java
License:Apache License
public static SecretKey getJobTokenSecretFromTokenBytes(ByteBuffer meta) throws IOException { DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(meta); Token<JobTokenIdentifier> jt = new Token<JobTokenIdentifier>(); jt.readFields(in);/* w w w . ja v a 2 s . c o m*/ SecretKey sk = JobTokenSecretManager.createSecretKey(jt.getPassword()); return sk; }
From source file:org.apache.tez.runtime.library.common.shuffle.ShuffleUtils.java
License:Apache License
public static int deserializeShuffleProviderMetaData(ByteBuffer meta) throws IOException { DataInputByteBuffer in = new DataInputByteBuffer(); try {//from w ww . j a v a2s . c om in.reset(meta); int port = in.readInt(); return port; } finally { in.close(); } }
From source file:org.apache.twill.internal.yarn.YarnUtils.java
License:Apache License
/** * Decodes {@link Credentials} from the given buffer. * If the buffer is null or empty, it returns an empty Credentials. *//*from w w w. j a v a 2s . co m*/ public static Credentials decodeCredentials(ByteBuffer buffer) throws IOException { Credentials credentials = new Credentials(); if (buffer != null && buffer.hasRemaining()) { DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(buffer); credentials.readTokenStorageStream(in); } return credentials; }