Get payload field and convert to byte array

@param inputRecord the input record which has the payload
@return the byte array of the payload in the input record
@deprecated use {@link #getFieldAsBytes(GenericRecord, String)}
544227
@Deprecated
  protected byte[] getPayloadBytes(GenericRecord inputRecord) {
    try {
      return getFieldAsBytes(inputRecord, payloadField);
    } catch (Exception e) {
      return null;
    }
  }
694452
@Override
  public Iterable<JsonObject> convertRecord(JsonArray outputSchema, String strInputRecord, WorkUnitState workUnit)
      throws DataConversionException {
    JsonParser jsonParser = new JsonParser();
    JsonObject inputRecord = (JsonObject) jsonParser.parse(strInputRecord);

    if (!this.unpackComplexSchemas) {
      return new SingleRecordIterable<>(inputRecord);
    }
    JsonSchema schema = new JsonSchema(outputSchema);
    JsonObject rec = parse(inputRecord, schema);
    return new SingleRecordIterable(rec);
  }
20649
public ByteBuffer getKey(String field) throws IOException {
        int hash = Arrays.hashCode(field.getBytes());
        return getKey(structure.keyHash2Index.get(hash));
    }
742070
protected static byte[] toArray(ByteBuffer... payload) {
        if (payload.length == 1) {
            ByteBuffer buf = payload[0];
            if (buf.hasArray() && buf.arrayOffset() == 0 && buf.position() == 0) {
                return buf.array();
            }
        }
        int size = (int) Buffers.remaining(payload);
        byte[] data = new byte[size];
        for (ByteBuffer buf : payload) {
            buf.get(data);
        }
        return data;
    }
520579
protected Field convertFieldSchema(Schema inputSchema, Field field, WorkUnitState workUnit)
      throws SchemaConversionException {
    if (field.name().equals(payloadField)) {
      // Create a payload field with latest schema
      return createLatestPayloadField(field);
    }
    // Make a copy of the field to the output schema
    return new Field(field.name(), field.schema(), field.doc(), field.defaultValue(), field.order());
  }
1078264
private ByteBuffer getBytesAccordingToType(String object, AbstractType<?> comparator)
    {
        if (comparator == null) // default comparator is BytesType
            comparator = BytesType.instance;

        try
        {
            return comparator.fromString(object);
        }
        catch (MarshalException e)
        {
            throw new RuntimeException(e);
        }
    }
309005
public static byte[] getBytes(InputStream in) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        pipeStream(in, out, 4096);
        return out.toByteArray();
    }
714565
public NetworkMemoryReport getMemoryReport(InputType inputType) {

        Map<String, MemoryReport> memoryReportMap = new LinkedHashMap<>();
        int nLayers = confs.size();
        for (int i = 0; i < nLayers; i++) {
            String layerName = confs.get(i).getLayer().getLayerName();
            if (layerName == null) {
                layerName = String.valueOf(i);
            }

            //Pass input type through preprocessor, if necessary
            InputPreProcessor preproc = getInputPreProcess(i);
            //TODO memory requirements for preprocessor
            if (preproc != null) {
                inputType = preproc.getOutputType(inputType);
            }

            LayerMemoryReport report = confs.get(i).getLayer().getMemoryReport(inputType);
            memoryReportMap.put(layerName, report);

            inputType = confs.get(i).getLayer().getOutputType(i, inputType);
        }

        return new NetworkMemoryReport(memoryReportMap, MultiLayerConfiguration.class, "MultiLayerNetwork", inputType);
    }
648990
private Payload getDataPayload(DigitalObject object)
			throws StorageException {
		for (String pid : object.getPayloadIdList()) {
			if (pid.endsWith(DATA_PAYLOAD_SUFFIX)) {
				return object.getPayload(pid);
			}
		}
		throw new StorageException("Data payload not found on storage!");
	}
1194084
@SuppressWarnings("PMD.AssignmentInOperand")
    private static byte[] asBytes(final InputStream input) throws IOException {
        input.reset();
        try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
            // @checkstyle MagicNumberCheck (1 line)
            final byte[] buffer = new byte[1024];
            int read;
            while ((read = input.read(buffer, 0, buffer.length)) != -1) {
                output.write(buffer, 0, read);
            }
            output.flush();
            return output.toByteArray();
        }
    }
785484
public static String readString(final DataInput in) throws IOException {

		if (in.readBoolean()) {
			final int length = in.readInt();
			if (length < 0) {
				throw new IOException("length of StringRecord is " + length);
			}

			final byte[] bytes = new byte[length];
			in.readFully(bytes, 0, length);
			return decode(bytes);
		}

		return null;
	}
968939
public static byte[] recordToByteArray(GenericRecord record) throws IOException {
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
      Encoder encoder = EncoderFactory.get().directBinaryEncoder(out, null);
      DatumWriter<GenericRecord> writer = new GenericDatumWriter<>(record.getSchema());
      writer.write(record, encoder);
      byte[] byteArray = out.toByteArray();
      return byteArray;
    }
  }
173466
@Override
	public Tuple2<K, V> deserialize(ConsumerRecord<byte[], byte[]> record) throws Exception {
		K key = null;
		V value = null;

		if (record.key() != null) {
			inputDeserializer.setBuffer(record.key());
			key = keySerializer.deserialize(inputDeserializer);
		}
		if (record.value() != null) {
			inputDeserializer.setBuffer(record.value());
			value = valueSerializer.deserialize(inputDeserializer);
		}
		return new Tuple2<>(key, value);
	}
252084
public static ConfigObjectRecord parseString( final String input )
    {
        final ConfigObjectRecord cor = new ConfigObjectRecord();
        try
        {
            cor.parseObjectRecord( input );
        }
        catch ( Exception e )
        {
            throw new IllegalArgumentException( "Data value is mailformed, invalid ConfigObjectRecord '" + input + "'" );
        }
        return cor;
    }
1001992
public static byte[] toBytes(TBase<?, ?> record) throws TException {
        if (record == null) {
            return null;
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        TTransport transport = new TIOStreamTransport(null, baos);
        TProtocol oProtocol = protocolFactory.getProtocol(transport);
        record.write(oProtocol);
        // baos.close();
        return baos.toByteArray();
    }
811656
public ByteBuffer getByteBuffer() throws InvalidRequestException
    {
        switch (type)
        {
            case STRING:
                return AsciiType.instance.fromString(text);
            case INTEGER:
                return IntegerType.instance.fromString(text);
            case UUID:
                // we specifically want the Lexical class here, not "UUIDType," because we're supposed to have
                // a uuid-shaped string here, and UUIDType also accepts integer or date strings (and turns them into version 1 uuids).
                return LexicalUUIDType.instance.fromString(text);
            case FLOAT:
              return FloatType.instance.fromString(text);
        }

        // FIXME: handle scenario that should never happen
        return null;
    }
267406
public int handlePutRawRecordData(Rec record)
    {
        int iErrorCode = Constant.NORMAL_RETURN;
        int iRecordCount = this.getRecordCount(record);
        
        Rec recTargetRecord = this.setDataIndex(RESET_INDEX, record);   // Reset index if multiple
        
        for (int index = 1; index <= iRecordCount; index++)
        {
            Rec recNext = this.setDataIndex(index, recTargetRecord);
            if (recNext == null)
                break;
            
            iErrorCode = super.handlePutRawRecordData(recNext);

            if (iErrorCode != Constant.NORMAL_RETURN)
                break;
        }
        this.setDataIndex(END_OF_NODES, recTargetRecord);
        return iErrorCode;
    }