Search in sources :

Example 21 with DataInputStream

use of java.io.DataInputStream in project pinot by linkedin.

the class AggregationPhaseMapOutputKey method fromBytes.

public static AggregationPhaseMapOutputKey fromBytes(byte[] buffer) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buffer));
    int length;
    int size;
    List<String> dimensions = new ArrayList<>();
    byte[] bytes;
    // time
    long time = dis.readLong();
    // dimensions size
    size = dis.readInt();
    // dimension value
    for (int i = 0; i < size; i++) {
        length = dis.readInt();
        bytes = new byte[length];
        dis.read(bytes);
        dimensions.add(new String(bytes));
    }
    AggregationPhaseMapOutputKey wrapper;
    wrapper = new AggregationPhaseMapOutputKey(time, dimensions);
    return wrapper;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DataInputStream(java.io.DataInputStream)

Example 22 with DataInputStream

use of java.io.DataInputStream in project pinot by linkedin.

the class AggregationPhaseMapOutputValue method fromBytes.

public static AggregationPhaseMapOutputValue fromBytes(byte[] buffer, List<MetricType> metricTypes) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buffer));
    int length;
    // metric values
    length = dis.readInt();
    Number[] metricValues = new Number[length];
    for (int i = 0; i < length; i++) {
        MetricType metricType = metricTypes.get(i);
        switch(metricType) {
            case SHORT:
                metricValues[i] = dis.readShort();
                break;
            case LONG:
                metricValues[i] = dis.readLong();
                break;
            case INT:
                metricValues[i] = dis.readInt();
                break;
            case FLOAT:
                metricValues[i] = dis.readFloat();
                break;
            case DOUBLE:
                metricValues[i] = dis.readDouble();
                break;
        }
    }
    AggregationPhaseMapOutputValue wrapper;
    wrapper = new AggregationPhaseMapOutputValue(metricValues, metricTypes);
    return wrapper;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MetricType(com.linkedin.thirdeye.hadoop.config.MetricType) DataInputStream(java.io.DataInputStream)

Example 23 with DataInputStream

use of java.io.DataInputStream in project pinot by linkedin.

the class TopKPhaseMapOutputValue method fromBytes.

public static TopKPhaseMapOutputValue fromBytes(byte[] buffer, List<MetricType> metricTypes) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buffer));
    int length;
    // metric values
    length = dis.readInt();
    Number[] metricValues = new Number[length];
    for (int i = 0; i < length; i++) {
        MetricType metricType = metricTypes.get(i);
        switch(metricType) {
            case SHORT:
                metricValues[i] = dis.readShort();
                break;
            case LONG:
                metricValues[i] = dis.readLong();
                break;
            case INT:
                metricValues[i] = dis.readInt();
                break;
            case FLOAT:
                metricValues[i] = dis.readFloat();
                break;
            case DOUBLE:
                metricValues[i] = dis.readDouble();
                break;
        }
    }
    TopKPhaseMapOutputValue wrapper;
    wrapper = new TopKPhaseMapOutputValue(metricValues, metricTypes);
    return wrapper;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MetricType(com.linkedin.thirdeye.hadoop.config.MetricType) DataInputStream(java.io.DataInputStream)

Example 24 with DataInputStream

use of java.io.DataInputStream in project hadoop by apache.

the class LeveldbRMStateStore method loadDelegationToken.

private RMDelegationTokenIdentifierData loadDelegationToken(byte[] data) throws IOException {
    RMDelegationTokenIdentifierData tokenData = new RMDelegationTokenIdentifierData();
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
    try {
        tokenData.readFields(in);
    } finally {
        IOUtils.cleanup(LOG, in);
    }
    return tokenData;
}
Also used : RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 25 with DataInputStream

use of java.io.DataInputStream in project hadoop by apache.

the class LeveldbRMStateStore method loadDelegationKey.

private DelegationKey loadDelegationKey(byte[] data) throws IOException {
    DelegationKey key = new DelegationKey();
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
    try {
        key.readFields(in);
    } finally {
        IOUtils.cleanup(LOG, in);
    }
    return key;
}
Also used : DelegationKey(org.apache.hadoop.security.token.delegation.DelegationKey) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Aggregations

DataInputStream (java.io.DataInputStream)2761 ByteArrayInputStream (java.io.ByteArrayInputStream)1139 IOException (java.io.IOException)1043 DataOutputStream (java.io.DataOutputStream)606 FileInputStream (java.io.FileInputStream)542 Test (org.junit.Test)533 ByteArrayOutputStream (java.io.ByteArrayOutputStream)368 File (java.io.File)274 BufferedInputStream (java.io.BufferedInputStream)253 InputStream (java.io.InputStream)245 ArrayList (java.util.ArrayList)200 EOFException (java.io.EOFException)154 DataInput (java.io.DataInput)141 FileNotFoundException (java.io.FileNotFoundException)131 ByteBuffer (java.nio.ByteBuffer)119 FileOutputStream (java.io.FileOutputStream)105 HashMap (java.util.HashMap)101 BufferedReader (java.io.BufferedReader)90 InputStreamReader (java.io.InputStreamReader)89 Socket (java.net.Socket)75