Java Code Examples for java.io.DataInput#readUnsignedByte()

The following examples show how to use java.io.DataInput#readUnsignedByte() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WriteMultipleRegistersRequest.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void readData(DataInput din) throws IOException {

    m_Reference = din.readShort();
    // read lengths
    int wc = din.readUnsignedShort();
    int bc = din.readUnsignedByte();

    // read values
    if (m_NonWordDataHandler == null) {
        m_Registers = new Register[wc];
        ProcessImageFactory pimf = ModbusCoupler.getReference().getProcessImageFactory();
        for (int i = 0; i < wc; i++) {
            m_Registers[i] = pimf.createRegister(din.readByte(), din.readByte());
        }
    } else {
        m_NonWordDataHandler.readData(din, m_Reference, wc);
    }
}
 
Example 2
Source File: JGenProg2017_00100_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Decodes a built DateTimeZone from the given stream, as encoded by
 * writeTo.
 *
 * @param in input stream to read encoded DateTimeZone from.
 * @param id time zone id to assign
 */
public static DateTimeZone readFrom(DataInput in, String id) throws IOException {
    switch (in.readUnsignedByte()) {
    case 'F':
        DateTimeZone fixed = new FixedDateTimeZone
            (id, in.readUTF(), (int)readMillis(in), (int)readMillis(in));
        if (fixed.equals(DateTimeZone.UTC)) {
            fixed = DateTimeZone.UTC;
        }
        return fixed;
    case 'C':
        return CachedDateTimeZone.forZone(PrecalculatedZone.readFrom(in, id));
    case 'P':
        return PrecalculatedZone.readFrom(in, id);
    default:
        throw new IOException("Invalid encoding");
    }
}
 
Example 3
Source File: DiskInitFile.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
static long readDiskRegionID(DataInput dis) throws IOException {
  int bytesToRead = dis.readUnsignedByte();
  if (bytesToRead <= DiskStoreImpl.MAX_RESERVED_DRID
      && bytesToRead >= DiskStoreImpl.MIN_RESERVED_DRID) {
    long result = dis.readByte(); // we want to sign extend this first byte
    bytesToRead--;
    while (bytesToRead > 0) {
      result <<= 8;
      result |= dis.readUnsignedByte(); // no sign extension
      bytesToRead--;
    }
    return result;
  } else {
    return bytesToRead;
  }
}
 
Example 4
Source File: jKali_0051_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Decodes a built DateTimeZone from the given stream, as encoded by
 * writeTo.
 *
 * @param in input stream to read encoded DateTimeZone from.
 * @param id time zone id to assign
 */
public static DateTimeZone readFrom(DataInput in, String id) throws IOException {
    switch (in.readUnsignedByte()) {
    case 'F':
        DateTimeZone fixed = new FixedDateTimeZone
            (id, in.readUTF(), (int)readMillis(in), (int)readMillis(in));
        if (fixed.equals(DateTimeZone.UTC)) {
            fixed = DateTimeZone.UTC;
        }
        return fixed;
    case 'C':
        return CachedDateTimeZone.forZone(PrecalculatedZone.readFrom(in, id));
    case 'P':
        return PrecalculatedZone.readFrom(in, id);
    default:
        throw new IOException("Invalid encoding");
    }
}
 
Example 5
Source File: jMutRepair_0029_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Reads encoding generated by writeMillis.
 */
static long readMillis(DataInput in) throws IOException {
    int v = in.readUnsignedByte();
    switch (v >> 6) {
    case 0: default:
        // Form 00 (6 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 6);
        return v * (30 * 60000L);

    case 1:
        // Form 01 (30 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 30);
        v |= (in.readUnsignedByte()) << 16;
        v |= (in.readUnsignedByte()) << 8;
        v |= (in.readUnsignedByte());
        return v * 60000L;

    case 2:
        // Form 10 (38 bits effective precision)
        long w = (((long)v) << (64 - 6)) >> (64 - 38);
        w |= (in.readUnsignedByte()) << 24;
        w |= (in.readUnsignedByte()) << 16;
        w |= (in.readUnsignedByte()) << 8;
        w |= (in.readUnsignedByte());
        return w * 1000L;

    case 3:
        // Form 11 (64 bits effective precision)
        return in.readLong();
    }
}
 
Example 6
Source File: JGenProg2017_00141_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Reads encoding generated by writeMillis.
 */
static long readMillis(DataInput in) throws IOException {
    int v = in.readUnsignedByte();
    switch (v >> 6) {
    case 0: default:
        // Form 00 (6 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 6);
        return v * (30 * 60000L);

    case 1:
        // Form 01 (30 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 30);
        v |= (in.readUnsignedByte()) << 16;
        v |= (in.readUnsignedByte()) << 8;
        v |= (in.readUnsignedByte());
        return v * 60000L;

    case 2:
        // Form 10 (38 bits effective precision)
        long w = (((long)v) << (64 - 6)) >> (64 - 38);
        w |= (in.readUnsignedByte()) << 24;
        w |= (in.readUnsignedByte()) << 16;
        w |= (in.readUnsignedByte()) << 8;
        w |= (in.readUnsignedByte());
        return w * 1000L;

    case 3:
        // Form 11 (64 bits effective precision)
        return in.readLong();
    }
}
 
Example 7
Source File: Arja_00146_s.java    From coming with MIT License 5 votes vote down vote up
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
    // Read string pool.
    int poolSize = in.readUnsignedShort();
    String[] pool = new String[poolSize];
    for (int i=0; i<poolSize; i++) {
        pool[i] = in.readUTF();
    }

    int size = in.readInt();
    long[] transitions = new long[size];
    int[] wallOffsets = new int[size];
    int[] standardOffsets = new int[size];
    String[] nameKeys = new String[size];
    
    for (int i=0; i<size; i++) {
        transitions[i] = readMillis(in);
        wallOffsets[i] = (int)readMillis(in);
        standardOffsets[i] = (int)readMillis(in);
        try {
            int index;
            if (poolSize < 256) {
                index = in.readUnsignedByte();
            } else {
                index = in.readUnsignedShort();
            }
            nameKeys[i] = pool[index];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IOException("Invalid encoding");
        }
    }

    DSTZone tailZone = null;
    if (in.readBoolean()) {
        tailZone = DSTZone.readFrom(in, id);
    }

    return new PrecalculatedZone
        (id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
 
Example 8
Source File: Cardumen_00136_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Reads encoding generated by writeMillis.
 */
static long readMillis(DataInput in) throws IOException {
    int v = in.readUnsignedByte();
    switch (v >> 6) {
    case 0: default:
        // Form 00 (6 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 6);
        return v * (30 * 60000L);

    case 1:
        // Form 01 (30 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 30);
        v |= (in.readUnsignedByte()) << 16;
        v |= (in.readUnsignedByte()) << 8;
        v |= (in.readUnsignedByte());
        return v * 60000L;

    case 2:
        // Form 10 (38 bits effective precision)
        long w = (((long)v) << (64 - 6)) >> (64 - 38);
        w |= (in.readUnsignedByte()) << 24;
        w |= (in.readUnsignedByte()) << 16;
        w |= (in.readUnsignedByte()) << 8;
        w |= (in.readUnsignedByte());
        return w * 1000L;

    case 3:
        // Form 11 (64 bits effective precision)
        return in.readLong();
    }
}
 
Example 9
Source File: Cardumen_00281_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Reads encoding generated by writeMillis.
 */
static long readMillis(DataInput in) throws IOException {
    int v = in.readUnsignedByte();
    switch (v >> 6) {
    case 0: default:
        // Form 00 (6 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 6);
        return v * (30 * 60000L);

    case 1:
        // Form 01 (30 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 30);
        v |= (in.readUnsignedByte()) << 16;
        v |= (in.readUnsignedByte()) << 8;
        v |= (in.readUnsignedByte());
        return v * 60000L;

    case 2:
        // Form 10 (38 bits effective precision)
        long w = (((long)v) << (64 - 6)) >> (64 - 38);
        w |= (in.readUnsignedByte()) << 24;
        w |= (in.readUnsignedByte()) << 16;
        w |= (in.readUnsignedByte()) << 8;
        w |= (in.readUnsignedByte());
        return w * 1000L;

    case 3:
        // Form 11 (64 bits effective precision)
        return in.readLong();
    }
}
 
Example 10
Source File: MethodParameters.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
MethodParameters(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool) throws IOException {
    super(Const.ATTR_METHOD_PARAMETERS, name_index, length, constant_pool);

    final int parameters_count = input.readUnsignedByte();
    parameters = new MethodParameter[parameters_count];
    for (int i = 0; i < parameters_count; i++) {
        parameters[i] = new MethodParameter(input);
    }
}
 
Example 11
Source File: jKali_0040_s.java    From coming with MIT License 5 votes vote down vote up
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
    // Read string pool.
    int poolSize = in.readUnsignedShort();
    String[] pool = new String[poolSize];
    for (int i=0; i<poolSize; i++) {
        pool[i] = in.readUTF();
    }

    int size = in.readInt();
    long[] transitions = new long[size];
    int[] wallOffsets = new int[size];
    int[] standardOffsets = new int[size];
    String[] nameKeys = new String[size];
    
    for (int i=0; i<size; i++) {
        transitions[i] = readMillis(in);
        wallOffsets[i] = (int)readMillis(in);
        standardOffsets[i] = (int)readMillis(in);
        try {
            int index;
            if (poolSize < 256) {
                index = in.readUnsignedByte();
            } else {
                index = in.readUnsignedShort();
            }
            nameKeys[i] = pool[index];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IOException("Invalid encoding");
        }
    }

    DSTZone tailZone = null;
    if (in.readBoolean()) {
        tailZone = DSTZone.readFrom(in, id);
    }

    return new PrecalculatedZone
        (id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
 
Example 12
Source File: Arja_0048_s.java    From coming with MIT License 5 votes vote down vote up
static OfYear readFrom(DataInput in) throws IOException {
    return new OfYear((char)in.readUnsignedByte(),
                      (int)in.readUnsignedByte(),
                      (int)in.readByte(),
                      (int)in.readUnsignedByte(),
                      in.readBoolean(),
                      (int)readMillis(in));
}
 
Example 13
Source File: Arja_0048_s.java    From coming with MIT License 5 votes vote down vote up
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
    // Read string pool.
    int poolSize = in.readUnsignedShort();
    String[] pool = new String[poolSize];
    for (int i=0; i<poolSize; i++) {
        pool[i] = in.readUTF();
    }

    int size = in.readInt();
    long[] transitions = new long[size];
    int[] wallOffsets = new int[size];
    int[] standardOffsets = new int[size];
    String[] nameKeys = new String[size];
    
    for (int i=0; i<size; i++) {
        transitions[i] = readMillis(in);
        wallOffsets[i] = (int)readMillis(in);
        standardOffsets[i] = (int)readMillis(in);
        try {
            int index;
            if (poolSize < 256) {
                index = in.readUnsignedByte();
            } else {
                index = in.readUnsignedShort();
            }
            nameKeys[i] = pool[index];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IOException("Invalid encoding");
        }
    }

    DSTZone tailZone = null;
    if (in.readBoolean()) {
        tailZone = DSTZone.readFrom(in, id);
    }

    return new PrecalculatedZone
        (id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
 
Example 14
Source File: JGenProg2017_0042_s.java    From coming with MIT License 5 votes vote down vote up
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
    // Read string pool.
    int poolSize = in.readUnsignedShort();
    String[] pool = new String[poolSize];
    for (int i=0; i<poolSize; i++) {
        pool[i] = in.readUTF();
    }

    int size = in.readInt();
    long[] transitions = new long[size];
    int[] wallOffsets = new int[size];
    int[] standardOffsets = new int[size];
    String[] nameKeys = new String[size];
    
    for (int i=0; i<size; i++) {
        transitions[i] = readMillis(in);
        wallOffsets[i] = (int)readMillis(in);
        standardOffsets[i] = (int)readMillis(in);
        try {
            int index;
            if (poolSize < 256) {
                index = in.readUnsignedByte();
            } else {
                index = in.readUnsignedShort();
            }
            nameKeys[i] = pool[index];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IOException("Invalid encoding");
        }
    }

    DSTZone tailZone = null;
    if (in.readBoolean()) {
        tailZone = DSTZone.readFrom(in, id);
    }

    return new PrecalculatedZone
        (id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
 
Example 15
Source File: Cardumen_00281_t.java    From coming with MIT License 5 votes vote down vote up
static OfYear readFrom(DataInput in) throws IOException {
    return new OfYear((char)in.readUnsignedByte(),
                      (int)in.readUnsignedByte(),
                      (int)in.readByte(),
                      (int)in.readUnsignedByte(),
                      in.readBoolean(),
                      (int)readMillis(in));
}
 
Example 16
Source File: Arja_0087_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Reads encoding generated by writeMillis.
 */
static long readMillis(DataInput in) throws IOException {
    int v = in.readUnsignedByte();
    switch (v >> 6) {
    case 0: default:
        // Form 00 (6 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 6);
        return v * (30 * 60000L);

    case 1:
        // Form 01 (30 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 30);
        v |= (in.readUnsignedByte()) << 16;
        v |= (in.readUnsignedByte()) << 8;
        v |= (in.readUnsignedByte());
        return v * 60000L;

    case 2:
        // Form 10 (38 bits effective precision)
        long w = (((long)v) << (64 - 6)) >> (64 - 38);
        w |= (in.readUnsignedByte()) << 24;
        w |= (in.readUnsignedByte()) << 16;
        w |= (in.readUnsignedByte()) << 8;
        w |= (in.readUnsignedByte());
        return w * 1000L;

    case 3:
        // Form 11 (64 bits effective precision)
        return in.readLong();
    }
}
 
Example 17
Source File: jMutRepair_0045_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Reads encoding generated by writeMillis.
 */
static long readMillis(DataInput in) throws IOException {
    int v = in.readUnsignedByte();
    switch (v >> 6) {
    case 0: default:
        // Form 00 (6 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 6);
        return v * (30 * 60000L);

    case 1:
        // Form 01 (30 bits effective precision)
        v = (v << (32 - 6)) >> (32 - 30);
        v |= (in.readUnsignedByte()) << 16;
        v |= (in.readUnsignedByte()) << 8;
        v |= (in.readUnsignedByte());
        return v * 60000L;

    case 2:
        // Form 10 (38 bits effective precision)
        long w = (((long)v) << (64 - 6)) >> (64 - 38);
        w |= (in.readUnsignedByte()) << 24;
        w |= (in.readUnsignedByte()) << 16;
        w |= (in.readUnsignedByte()) << 8;
        w |= (in.readUnsignedByte());
        return w * 1000L;

    case 3:
        // Form 11 (64 bits effective precision)
        return in.readLong();
    }
}
 
Example 18
Source File: Arja_00160_t.java    From coming with MIT License 5 votes vote down vote up
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
    // Read string pool.
    int poolSize = in.readUnsignedShort();
    String[] pool = new String[poolSize];
    for (int i=0; i<poolSize; i++) {
        pool[i] = in.readUTF();
    }

    int size = in.readInt();
    long[] transitions = new long[size];
    int[] wallOffsets = new int[size];
    int[] standardOffsets = new int[size];
    String[] nameKeys = new String[size];
    
    for (int i=0; i<size; i++) {
        transitions[i] = readMillis(in);
        wallOffsets[i] = (int)readMillis(in);
        standardOffsets[i] = (int)readMillis(in);
        try {
            int index;
            if (poolSize < 256) {
                index = in.readUnsignedByte();
            } else {
                index = in.readUnsignedShort();
            }
            nameKeys[i] = pool[index];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IOException("Invalid encoding");
        }
    }

    DSTZone tailZone = null;
    if (in.readBoolean()) {
        tailZone = DSTZone.readFrom(in, id);
    }

    return new PrecalculatedZone
        (id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
 
Example 19
Source File: SmartVLongSerializer.java    From mph-table with Apache License 2.0 4 votes vote down vote up
/**
 * Decoding the variable-length integer. Suppose the value of the first byte
 * is FB, and the following bytes are NB[*].
 * <ul>
 * <li>if (FB &gt;= -32), return (long)FB;
 * <li>if (FB in [-72, -33]), return (FB+52)&lt;&lt;8 + NB[0]&amp;0xff;
 * <li>if (FB in [-104, -73]), return (FB+88)&lt;&lt;16 + (NB[0]&amp;0xff)&lt;&lt;8 +
 * NB[1]&amp;0xff;
 * <li>if (FB in [-120, -105]), return (FB+112)&lt;&lt;24 + (NB[0]&amp;0xff)&lt;&lt;16 +
 * (NB[1]&amp;0xff)&lt;&lt;8 + NB[2]&amp;0xff;
 * <li>if (FB in [-128, -121]), return interpret NB[FB+129] as a signed
 * big-endian integer.
 * </ul>
 *
 * @param in input stream
 * @return the decoded long integer.
 * @throws java.io.IOException if unable to read from in
 */

public static long readVLong(final DataInput in) throws IOException {
    final int firstByte = in.readByte();
    if (firstByte >= -32) {
        return firstByte;
    }

    switch ((firstByte + 128) / 8) {
        case 11:
        case 10:
        case 9:
        case 8:
        case 7:
            return ((firstByte + 52) << 8) | in.readUnsignedByte();
        case 6:
        case 5:
        case 4:
        case 3:
            return ((firstByte + 88) << 16) | in.readUnsignedShort();
        case 2:
        case 1:
            return ((firstByte + 112) << 24) | (in.readUnsignedShort() << 8)
                    | in.readUnsignedByte();
        case 0:
            final int len = firstByte + 129;
            switch (len) {
                case 4:
                    return in.readInt();
                case 5:
                    return (((long) in.readInt()) << 8) | in.readUnsignedByte();
                case 6:
                    return (((long) in.readInt()) << 16) | in.readUnsignedShort();
                case 7:
                    return (((long) in.readInt()) << 24) | (in.readUnsignedShort() << 8)
                            | in.readUnsignedByte();
                case 8:
                    return in.readLong();
                default:
                    throw new IOException("Corrupted VLong encoding");
            }
        default:
            throw new RuntimeException("Internal error");
    }
}
 
Example 20
Source File: TypeAnnotationInfo.java    From yGuard with MIT License 4 votes vote down vote up
private void read(DataInput din) throws java.io.IOException {

    u1TargetType = din.readUnsignedByte();

    switch (u1TargetType) {
      //
      // https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.20-400
      //
      case 0x00:
        // type parameter declaration of generic class or interface => type_parameter_target
      case 0x01:
        // type parameter declaration of generic method or constructor => type_parameter_target
        u1TypeParameterIndex = din.readUnsignedByte();
        break;
      case 0x10:
        // type in extends or implements clause of class declaration (including the direct superclass 
        // or direct superinterface of an anonymous class declaration), or in extends clause of interface declaration
        // => supertype_target
        u2SupertypeIndex = din.readUnsignedShort();
        break;
      case 0x11:
        // type in bound of type parameter declaration of generic class or interface
        // => type_parameter_bound_target 
      case 0x12:
        // type in bound of type parameter declaration of generic method or constructor
        // => type_parameter_bound_target 
        u1TypeParameterIndex = din.readUnsignedByte();
        u1TypeBoundIndex = din.readUnsignedByte();
        break;
      case 0x13:
        // type in field declaration => empty_target
      case 0x14:  
        // return type of method, or type of newly constructed object => empty_target
      case 0x15:  
        // receiver type of method or constructor => empty_target
        break;
      case 0x16:
        // type in formal parameter declaration of method, constructor, or lambda expression => formal_parameter_target
        u1FormalParameterIndex = din.readUnsignedByte();
        break;
      case 0x17:
        // type in throws clause of method or constructor => throws_target
        u2ThrowsTypeIndex = din.readUnsignedShort();
        break;
      //  
      // https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.20-410
      //
      case 0x40:
        // type in local variable declaration => localvar_target
      case 0x41:
        // type in resource variable declaration => localvar_target
        localvarTarget = new LocalvarTarget();
        localvarTarget.readInfo(din);
        break;
      case 0x42:
        // type in exception parameter declaration	
        u2ExceptionTableIndex = din.readUnsignedShort();
        break;
      case 0x43:
        // type in instanceof expression => offset_target
      case 0x44:
        // type in new expression => offset_target
      case 0x45:
        // type in method reference expression using ::new => offset_target
      case 0x46:
        // type in method reference expression using ::Identifier => offset_target
        u2Offset = din.readUnsignedShort();
        break;
      case 0x47:
        // type in cast expression => type_argument_target
      case 0x48:
        // type argument for generic constructor in new expression or explicit constructor invocation statement => type_argument_target
      case 0x49:
        // type argument for generic method in method invocation expression => type_argument_target
      case 0x4A:
        // type argument for generic constructor in method reference expression using ::new => type_argument_target
      case 0x4B:
        // type argument for generic method in method reference expression using ::Identifier => type_argument_target
        u2Offset = din.readUnsignedShort();
        u1TypeArgumentIndex = din.readUnsignedByte();
        break;
      default:
        throw new IllegalArgumentException("Unkown annotation target type: 0x"+Integer.toHexString(u1TargetType)+"");
    }

    targetPath = new TypePath();
    targetPath.readInfo(din);

    u2TypeIndex = din.readUnsignedShort();
    u2NumElementValuePairs = din.readUnsignedShort();

    elementValuePairs = new ElementValuePairInfo[u2NumElementValuePairs];
    for (int i = 0; i < u2NumElementValuePairs; i++) {
      elementValuePairs[i] = ElementValuePairInfo.create(din);
    }
  }