Example usage for java.io DataInput readShort

List of usage examples for java.io DataInput readShort

Introduction

In this page you can find the example usage for java.io DataInput readShort.

Prototype

short readShort() throws IOException;

Source Link

Document

Reads two input bytes and returns a short value.

Usage

From source file:org.apache.carbondata.core.metadata.blocklet.BlockletInfo.java

@Override
public void readFields(DataInput input) throws IOException {
    dimensionOffset = input.readLong();/*  w  w  w. ja  v  a 2s .  c  o  m*/
    measureOffsets = input.readLong();
    int dimensionChunkOffsetsSize = input.readShort();
    dimensionChunkOffsets = new ArrayList<>(dimensionChunkOffsetsSize);
    for (int i = 0; i < dimensionChunkOffsetsSize; i++) {
        dimensionChunkOffsets.add(input.readLong());
    }
    dimensionChunksLength = new ArrayList<>(dimensionChunkOffsetsSize);
    for (int i = 0; i < dimensionChunkOffsetsSize; i++) {
        dimensionChunksLength.add(input.readInt());
    }

    short measureChunkOffsetsSize = input.readShort();
    measureChunkOffsets = new ArrayList<>(measureChunkOffsetsSize);
    for (int i = 0; i < measureChunkOffsetsSize; i++) {
        measureChunkOffsets.add(input.readLong());
    }
    measureChunksLength = new ArrayList<>(measureChunkOffsetsSize);
    for (int i = 0; i < measureChunkOffsetsSize; i++) {
        measureChunksLength.add(input.readInt());
    }
    readChunkInfoForOlderVersions(input);
    final boolean isSortedPresent = input.readBoolean();
    if (isSortedPresent) {
        this.isSorted = input.readBoolean();
    }
    numberOfRowsPerPage = new int[input.readShort()];
    for (int i = 0; i < numberOfRowsPerPage.length; i++) {
        numberOfRowsPerPage[i] = input.readInt();
    }
}

From source file:org.apache.carbondata.core.metadata.blocklet.BlockletInfo.java

/**
 * Deserialize datachunks as well for older versions like V1 and V2
 *///  w ww . ja va2s.  c om
private void readChunkInfoForOlderVersions(DataInput input) throws IOException {
    short dimChunksSize = input.readShort();
    dimensionColumnChunk = new ArrayList<>(dimChunksSize);
    for (int i = 0; i < dimChunksSize; i++) {
        byte[] bytes = new byte[input.readInt()];
        input.readFully(bytes);
        dimensionColumnChunk.add(deserializeDataChunk(bytes));
    }
    short msrChunksSize = input.readShort();
    measureColumnChunk = new ArrayList<>(msrChunksSize);
    for (int i = 0; i < msrChunksSize; i++) {
        byte[] bytes = new byte[input.readInt()];
        input.readFully(bytes);
        measureColumnChunk.add(deserializeDataChunk(bytes));
    }
}

From source file:org.apache.carbondata.core.metadata.schema.table.DataMapSchema.java

@Override
public void readFields(DataInput in) throws IOException {
    this.dataMapName = in.readUTF();
    this.providerName = in.readUTF();
    boolean isRelationIdentifierExists = in.readBoolean();
    if (isRelationIdentifierExists) {
        this.relationIdentifier = new RelationIdentifier(null, null, null);
        this.relationIdentifier.readFields(in);
    }/*from w  w  w  .ja  v a2  s .  c  om*/
    boolean isChildSchemaExists = in.readBoolean();
    if (isChildSchemaExists) {
        this.childSchema = new TableSchema();
        this.childSchema.readFields(in);
    }

    int mapSize = in.readShort();
    this.properties = new HashMap<>(mapSize);
    for (int i = 0; i < mapSize; i++) {
        String key = in.readUTF();
        String value = in.readUTF();
        this.properties.put(key, value);
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static Object readDSFID(final DataInput in) throws IOException, ClassNotFoundException {
    checkIn(in);//from   w  ww. j  a  v a2 s  .com
    byte header = in.readByte();
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "readDSFID: header={}", header);
    }
    if (header == DS_FIXED_ID_BYTE) {
        return DSFIDFactory.create(in.readByte(), in);
    } else if (header == DS_FIXED_ID_SHORT) {
        return DSFIDFactory.create(in.readShort(), in);
    } else if (header == DS_NO_FIXED_ID) {
        return readDataSerializableFixedID(in);
    } else if (header == DS_FIXED_ID_INT) {
        return DSFIDFactory.create(in.readInt(), in);
    } else {
        throw new IllegalStateException("unexpected byte: " + header + " while reading dsfid");
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static int readDSFIDHeader(final DataInput in) throws IOException {
    checkIn(in);//  w w w .jav  a  2 s  . c  o m
    byte header = in.readByte();
    if (header == DS_FIXED_ID_BYTE) {
        return in.readByte();
    } else if (header == DS_FIXED_ID_SHORT) {
        return in.readShort();
    } else if (header == DS_NO_FIXED_ID) {
        // is that correct??
        return Integer.MAX_VALUE;
    } else if (header == DS_FIXED_ID_INT) {
        return in.readInt();
    } else {
        throw new IllegalStateException("unexpected byte: " + header + " while reading dsfid");
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static Object basicReadObject(final DataInput in) throws IOException, ClassNotFoundException {
    checkIn(in);//from www .j a v a  2  s. c  o m

    // Read the header byte
    byte header = in.readByte();
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "basicReadObject: header={}", header);
    }
    switch (header) {
    case DS_FIXED_ID_BYTE:
        return DSFIDFactory.create(in.readByte(), in);
    case DS_FIXED_ID_SHORT:
        return DSFIDFactory.create(in.readShort(), in);
    case DS_FIXED_ID_INT:
        return DSFIDFactory.create(in.readInt(), in);
    case DS_NO_FIXED_ID:
        return readDataSerializableFixedID(in);
    case NULL:
        return null;
    case NULL_STRING:
    case STRING:
    case HUGE_STRING:
    case STRING_BYTES:
    case HUGE_STRING_BYTES:
        return readString(in, header);
    case CLASS:
        return readClass(in);
    case DATE:
        return readDate(in);
    case FILE:
        return readFile(in);
    case INET_ADDRESS:
        return readInetAddress(in);
    case BOOLEAN:
        return readBoolean(in);
    case CHARACTER:
        return readCharacter(in);
    case BYTE:
        return readByte(in);
    case SHORT:
        return readShort(in);
    case INTEGER:
        return readInteger(in);
    case LONG:
        return readLong(in);
    case FLOAT:
        return readFloat(in);
    case DOUBLE:
        return readDouble(in);
    case BYTE_ARRAY:
        return readByteArray(in);
    case ARRAY_OF_BYTE_ARRAYS:
        return readArrayOfByteArrays(in);
    case SHORT_ARRAY:
        return readShortArray(in);
    case STRING_ARRAY:
        return readStringArray(in);
    case INT_ARRAY:
        return readIntArray(in);
    case LONG_ARRAY:
        return readLongArray(in);
    case FLOAT_ARRAY:
        return readFloatArray(in);
    case DOUBLE_ARRAY:
        return readDoubleArray(in);
    case BOOLEAN_ARRAY:
        return readBooleanArray(in);
    case CHAR_ARRAY:
        return readCharArray(in);
    case OBJECT_ARRAY:
        return readObjectArray(in);
    case ARRAY_LIST:
        return readArrayList(in);
    case LINKED_LIST:
        return readLinkedList(in);
    case HASH_SET:
        return readHashSet(in);
    case LINKED_HASH_SET:
        return readLinkedHashSet(in);
    case HASH_MAP:
        return readHashMap(in);
    case IDENTITY_HASH_MAP:
        return readIdentityHashMap(in);
    case HASH_TABLE:
        return readHashtable(in);
    case CONCURRENT_HASH_MAP:
        return readConcurrentHashMap(in);
    case PROPERTIES:
        return readProperties(in);
    case TIME_UNIT:
        return readTimeUnit(in);
    case USER_CLASS:
        return readUserObject(in, in.readByte());
    case USER_CLASS_2:
        return readUserObject(in, in.readShort());
    case USER_CLASS_4:
        return readUserObject(in, in.readInt());
    case VECTOR:
        return readVector(in);
    case STACK:
        return readStack(in);
    case TREE_MAP:
        return readTreeMap(in);
    case TREE_SET:
        return readTreeSet(in);
    case BOOLEAN_TYPE:
        return Boolean.TYPE;
    case CHARACTER_TYPE:
        return Character.TYPE;
    case BYTE_TYPE:
        return Byte.TYPE;
    case SHORT_TYPE:
        return Short.TYPE;
    case INTEGER_TYPE:
        return Integer.TYPE;
    case LONG_TYPE:
        return Long.TYPE;
    case FLOAT_TYPE:
        return Float.TYPE;
    case DOUBLE_TYPE:
        return Double.TYPE;
    case VOID_TYPE:
        return Void.TYPE;

    case USER_DATA_SERIALIZABLE:
        return readUserDataSerializable(in, in.readByte());
    case USER_DATA_SERIALIZABLE_2:
        return readUserDataSerializable(in, in.readShort());
    case USER_DATA_SERIALIZABLE_4:
        return readUserDataSerializable(in, in.readInt());

    case DATA_SERIALIZABLE:
        return readDataSerializable(in);

    case SERIALIZABLE: {
        final boolean isDebugEnabled_SERIALIZER = logger.isTraceEnabled(LogMarker.SERIALIZER);
        Object serializableResult;
        if (in instanceof DSObjectInputStream) {
            serializableResult = ((DSObjectInputStream) in).readObject();
        } else {
            InputStream stream;
            if (in instanceof InputStream) {
                stream = (InputStream) in;
            } else {
                stream = new InputStream() {
                    @Override
                    public int read() throws IOException {
                        try {
                            return in.readUnsignedByte(); // fix for bug 47249
                        } catch (EOFException ignored) {
                            return -1;
                        }
                    }

                };
            }

            ObjectInput ois = new DSObjectInputStream(stream);
            if (stream instanceof VersionedDataStream) {
                Version v = ((VersionedDataStream) stream).getVersion();
                if (v != null && v != Version.CURRENT) {
                    ois = new VersionedObjectInput(ois, v);
                }
            }

            serializableResult = ois.readObject();

            if (isDebugEnabled_SERIALIZER) {
                logger.trace(LogMarker.SERIALIZER, "Read Serializable object: {}", serializableResult);
            }
        }
        if (isDebugEnabled_SERIALIZER) {
            logger.trace(LogMarker.SERIALIZER, "deserialized instanceof {}", serializableResult.getClass());
        }
        return serializableResult;
    }
    case PDX:
        return readPdxSerializable(in);
    case PDX_ENUM:
        return readPdxEnum(in);
    case GEMFIRE_ENUM:
        return readGemFireEnum(in);
    case PDX_INLINE_ENUM:
        return readPdxInlineEnum(in);
    case BIG_INTEGER:
        return readBigInteger(in);
    case BIG_DECIMAL:
        return readBigDecimal(in);
    case UUID:
        return readUUID(in);
    case TIMESTAMP:
        return readTimestamp(in);
    default:
        String s = "Unknown header byte: " + header;
        throw new IOException(s);
    }
}

From source file:org.apache.hadoop.fs.permission.FsPermission.java

/** {@inheritDoc} */
public void readFields(DataInput in) throws IOException {
    fromShort(in.readShort());
}

From source file:org.apache.hadoop.hbase.filter.RowListFilter.java

@Override
public void readFields(DataInput din) throws IOException {
    int pos = din.readInt();
    int sz = din.readInt();
    this.bytesSet = new ArrayList<byte[]>(sz);
    for (int i = 0; i < sz; ++i) {
        short bsz = din.readShort();
        byte[] b = new byte[bsz];
        din.readFully(b);//from   ww w . j  a  v a2s. c  om
        bytesSet.add(b);
    }
    log.debug("Size of bytesSet is: " + bytesSet.size());
    this.bytesSetIterator = bytesSet.listIterator(pos);
    if (bytesSetIterator.hasNext()) {
        this.rowComparator = new BinaryComparator(bytesSetIterator.next());
    } else {
        this.hasMoreRows = false;
    }
}

From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Read a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding.//from w  w w.j  a v  a2s.  c om
 * @param in
 * @param objectWritable
 * @param conf
 * @return the object
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, HbaseObjectWritable objectWritable, Configuration conf)
        throws IOException {
    Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in));
    Object instance;
    if (declaredClass.isPrimitive()) { // primitive types
        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isArray()) { // array
        if (declaredClass.equals(byte[].class)) {
            instance = Bytes.readByteArray(in);
        } else if (declaredClass.equals(Result[].class)) {
            instance = Result.readArray(in);
        } else {
            int length = in.readInt();
            instance = Array.newInstance(declaredClass.getComponentType(), length);
            for (int i = 0; i < length; i++) {
                Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE
        Class<?> componentType = readClass(conf, in);
        int length = in.readInt();
        instance = Array.newInstance(componentType, length);
        for (int i = 0; i < length; i++) {
            Array.set(instance, i, readObject(in, conf));
        }
    } else if (List.class.isAssignableFrom(declaredClass)) { // List
        int length = in.readInt();
        instance = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            ((ArrayList) instance).add(readObject(in, conf));
        }
    } else if (declaredClass == String.class) { // String
        instance = Text.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in));
    } else if (declaredClass == Message.class) {
        String className = Text.readString(in);
        try {
            declaredClass = getClassByName(conf, className);
            instance = tryInstantiateProtobuf(declaredClass, in);
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find class " + className, e);
            throw new IOException("Can't find class " + className, e);
        }
    } else { // Writable or Serializable
        Class instanceClass = null;
        int b = (byte) WritableUtils.readVInt(in);
        if (b == NOT_ENCODED) {
            String className = Text.readString(in);
            try {
                instanceClass = getClassByName(conf, className);
            } catch (ClassNotFoundException e) {
                LOG.error("Can't find class " + className, e);
                throw new IOException("Can't find class " + className, e);
            }
        } else {
            instanceClass = CODE_TO_CLASS.get(b);
        }
        if (Writable.class.isAssignableFrom(instanceClass)) {
            Writable writable = WritableFactories.newInstance(instanceClass, conf);
            try {
                writable.readFields(in);
            } catch (Exception e) {
                LOG.error("Error in readFields", e);
                throw new IOException("Error in readFields", e);
            }
            instance = writable;
            if (instanceClass == NullInstance.class) { // null
                declaredClass = ((NullInstance) instance).declaredClass;
                instance = null;
            }
        } else {
            int length = in.readInt();
            byte[] objectBytes = new byte[length];
            in.readFully(objectBytes);
            ByteArrayInputStream bis = null;
            ObjectInputStream ois = null;
            try {
                bis = new ByteArrayInputStream(objectBytes);
                ois = new ObjectInputStream(bis);
                instance = ois.readObject();
            } catch (ClassNotFoundException e) {
                LOG.error("Class not found when attempting to deserialize object", e);
                throw new IOException("Class not found when attempting to " + "deserialize object", e);
            } finally {
                if (bis != null)
                    bis.close();
                if (ois != null)
                    ois.close();
            }
        }
    }
    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }
    return instance;
}

From source file:org.apache.hadoop.hbase.security.access.HbaseObjectWritableFor96Migration.java

/**
 * Read a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding.//  w w  w .j  a v a 2  s.  co  m
 * @param in
 * @param objectWritable
 * @param conf
 * @return the object
 * @throws IOException
 */
@SuppressWarnings("unchecked")
static Object readObject(DataInput in, HbaseObjectWritableFor96Migration objectWritable, Configuration conf)
        throws IOException {
    Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in));
    Object instance;
    if (declaredClass.isPrimitive()) { // primitive types
        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isArray()) { // array
        if (declaredClass.equals(byte[].class)) {
            instance = Bytes.readByteArray(in);
        } else {
            int length = in.readInt();
            instance = Array.newInstance(declaredClass.getComponentType(), length);
            for (int i = 0; i < length; i++) {
                Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE
        Class<?> componentType = readClass(conf, in);
        int length = in.readInt();
        instance = Array.newInstance(componentType, length);
        for (int i = 0; i < length; i++) {
            Array.set(instance, i, readObject(in, conf));
        }
    } else if (List.class.isAssignableFrom(declaredClass)) { // List
        int length = in.readInt();
        instance = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            ((ArrayList) instance).add(readObject(in, conf));
        }
    } else if (declaredClass == String.class) { // String
        instance = Text.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in));
    } else if (declaredClass == Message.class) {
        String className = Text.readString(in);
        try {
            declaredClass = getClassByName(conf, className);
            instance = tryInstantiateProtobuf(declaredClass, in);
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find class " + className, e);
            throw new IOException("Can't find class " + className, e);
        }
    } else if (Scan.class.isAssignableFrom(declaredClass)) {
        int length = in.readInt();
        byte[] scanBytes = new byte[length];
        in.readFully(scanBytes);
        ClientProtos.Scan.Builder scanProto = ClientProtos.Scan.newBuilder();
        instance = ProtobufUtil.toScan(scanProto.mergeFrom(scanBytes).build());
    } else { // Writable or Serializable
        Class instanceClass = null;
        int b = (byte) WritableUtils.readVInt(in);
        if (b == NOT_ENCODED) {
            String className = Text.readString(in);
            try {
                instanceClass = getClassByName(conf, className);
            } catch (ClassNotFoundException e) {
                LOG.error("Can't find class " + className, e);
                throw new IOException("Can't find class " + className, e);
            }
        } else {
            instanceClass = CODE_TO_CLASS.get(b);
        }
        if (Writable.class.isAssignableFrom(instanceClass)) {
            Writable writable = WritableFactories.newInstance(instanceClass, conf);
            try {
                writable.readFields(in);
            } catch (Exception e) {
                LOG.error("Error in readFields", e);
                throw new IOException("Error in readFields", e);
            }
            instance = writable;
            if (instanceClass == NullInstance.class) { // null
                declaredClass = ((NullInstance) instance).declaredClass;
                instance = null;
            }
        } else {
            int length = in.readInt();
            byte[] objectBytes = new byte[length];
            in.readFully(objectBytes);
            ByteArrayInputStream bis = null;
            ObjectInputStream ois = null;
            try {
                bis = new ByteArrayInputStream(objectBytes);
                ois = new ObjectInputStream(bis);
                instance = ois.readObject();
            } catch (ClassNotFoundException e) {
                LOG.error("Class not found when attempting to deserialize object", e);
                throw new IOException("Class not found when attempting to " + "deserialize object", e);
            } finally {
                if (bis != null)
                    bis.close();
                if (ois != null)
                    ois.close();
            }
        }
    }
    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }
    return instance;
}