java.io.DataInput#readUnsignedByte ( )源码实例Demo

下面列出了java.io.DataInput#readUnsignedByte ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
    }
}
 
源代码2 项目: coming   文件: JGenProg2017_00100_s.java
/**
 * 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");
    }
}
 
源代码3 项目: gemfirexd-oss   文件: DiskInitFile.java
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;
  }
}
 
源代码4 项目: coming   文件: jKali_0051_s.java
/**
 * 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");
    }
}
 
源代码5 项目: coming   文件: JGenProg2017_00141_s.java
/**
 * 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();
    }
}
 
源代码6 项目: coming   文件: Arja_00160_t.java
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);
}
 
源代码7 项目: coming   文件: jMutRepair_0045_s.java
/**
 * 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();
    }
}
 
源代码8 项目: coming   文件: Arja_0087_s.java
/**
 * 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();
    }
}
 
源代码9 项目: coming   文件: Cardumen_00281_t.java
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));
}
 
源代码10 项目: coming   文件: JGenProg2017_0042_s.java
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);
}
 
源代码11 项目: coming   文件: Arja_0048_s.java
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);
}
 
源代码12 项目: coming   文件: Arja_0048_s.java
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));
}
 
源代码13 项目: coming   文件: jKali_0040_s.java
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);
}
 
源代码14 项目: commons-bcel   文件: MethodParameters.java
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);
    }
}
 
源代码15 项目: coming   文件: Cardumen_00281_t.java
/**
 * 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();
    }
}
 
源代码16 项目: coming   文件: Cardumen_00136_s.java
/**
 * 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();
    }
}
 
源代码17 项目: coming   文件: Arja_00146_s.java
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);
}
 
源代码18 项目: coming   文件: jMutRepair_0029_s.java
/**
 * 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();
    }
}
 
源代码19 项目: yGuard   文件: TypeAnnotationInfo.java
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);
    }
  }
 
源代码20 项目: mph-table   文件: SmartVLongSerializer.java
/**
 * 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");
    }
}