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

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

源代码1 项目: happy-dns-android   文件: DnsMessage.java
/**
 * Parse a domain name starting at the current offset and moving the input
 * stream pointer past this domain name (even if cross references occure).
 *
 * @param dis  The input stream.
 * @param data The raw data (for cross references).
 * @return The domain name string.
 * @throws IOException Should never happen.
 */
private static String readName(DataInputStream dis, byte data[])
        throws IOException {
    int c = dis.readUnsignedByte();
    if ((c & 0xc0) == 0xc0) {
        c = ((c & 0x3f) << 8) + dis.readUnsignedByte();
        HashSet<Integer> jumps = new HashSet<Integer>();
        jumps.add(c);
        return readName(data, c, jumps);
    }
    if (c == 0) {
        return "";
    }
    byte b[] = new byte[c];
    dis.readFully(b);
    String s = IDN.toUnicode(new String(b));
    String t = readName(dis, data);
    if (t.length() > 0) {
        s = s + "." + t;
    }
    return s;
}
 
源代码2 项目: mochadoom   文件: VanillaDSGHeader.java
@Override
public void read(DataInputStream f)
        throws IOException {
    name= DoomIO.readNullTerminatedString(f,SAVESTRINGSIZE);
    vcheck=DoomIO.readNullTerminatedString(f,VERSIONSIZE);
    gameskill=skill_t.values()[f.readUnsignedByte()]; 
    gameepisode=f.readByte();
    gamemap=f.readByte();
    for (int i=0 ; i<MAXPLAYERS ; i++) 
        playeringame[i]=f.readBoolean(); 
 
    // get the times 
    int a = f.readUnsignedByte(); 
    int b = f.readUnsignedByte();
    int c = f.readUnsignedByte();
    // Quite anomalous, leveltime is stored as a BIG ENDIAN, 24-bit unsigned integer :-S
    leveltime = (a<<16) | (b<<8) | c; 
        
}
 
源代码3 项目: j60870   文件: APdu.java
private static int readApduLength(DataInputStream is) throws IOException {
    int length = is.readUnsignedByte();

    if (length < MIN_APDU_LENGTH || length > MAX_APDU_LENGTH) {
        String msg = MessageFormat
                .format("APDU has an invalid length must be between 4 and 253.\nReceived length was: {0}.", length);
        throw new IOException(msg);
    }
    return length;
}
 
源代码4 项目: jmg   文件: PWheel.java
public int read(DataInputStream dis) throws IOException{
       // Pitch wheel change is a 14 bit value stored in two bytes,
       // least significant first
	this.value = (int) dis.readUnsignedByte();
       this.value += ((int) dis.readUnsignedByte()) * 128;
	return 1;
}
 
源代码5 项目: jmg   文件: TempoEvent.java
/** Read the contends of this object in from disk */
public int read(DataInputStream dis) throws IOException{
	int b1 = (int)dis.readUnsignedByte();
	int b2 = (int)dis.readUnsignedByte();
	int b3 = (int)dis.readUnsignedByte();
	int temp = (b1<<16) + (b2<<8) + b3;
	this.tempo = (double) (1000000f / (float)temp * 60.0f);
	return 3;
}
 
源代码6 项目: bazel   文件: PersistentMap.java
private boolean hasEntries(DataInputStream in, boolean failFast) throws IOException {
  if (in.available() <= 0) {
    return false;
  } else if (in.readUnsignedByte() != ENTRY_MAGIC) {
    if (failFast) {
      throw new IOException("Corrupted entry separator");
    } else {
      return false;
    }
  }
  return true;
}
 
源代码7 项目: NoteBlockAPI   文件: NBSDecoder.java
private static int readInt(DataInputStream dataInputStream) throws IOException {
	int byte1 = dataInputStream.readUnsignedByte();
	int byte2 = dataInputStream.readUnsignedByte();
	int byte3 = dataInputStream.readUnsignedByte();
	int byte4 = dataInputStream.readUnsignedByte();
	return (byte1 + (byte2 << 8) + (byte3 << 16) + (byte4 << 24));
}
 
源代码8 项目: j60870   文件: IeFileReadyQualifier.java
static InformationElement decode(DataInputStream is) throws IOException {
    int b1 = is.readUnsignedByte();
    int value = b1 & 0x7f;
    boolean negativeConfirm = ((b1 & 0x80) == 0x80);

    return new IeFileReadyQualifier(value, negativeConfirm);
}
 
源代码9 项目: jmg   文件: TimeSig.java
/**
        * Read the contends of this objec in from disk
        * Implemented by Sean T. Hayes
        * @param dis a stream of MIDI data
        * @return the number of bytes read
        * @throws java.io.IOException
        */
public int read(DataInputStream dis) throws IOException
       {
           numerator = (short)dis.readUnsignedByte();
           int power = (short)dis.readUnsignedByte();
           denominator = 1 << power; //  = Math.pow( 2, power )
           metronomePulse = dis.readUnsignedByte();
           thirtySecondNotesPerBeat = dis.readUnsignedByte();
           return 4;
}
 
源代码10 项目: packagedrone   文件: RangeDecoderFromStream.java
public RangeDecoderFromStream(InputStream in) throws IOException {
    inData = new DataInputStream(in);

    if (inData.readUnsignedByte() != 0x00)
        throw new CorruptedInputException();

    code = inData.readInt();
    range = 0xFFFFFFFF;
}
 
源代码11 项目: bistoury   文件: StructTypeAnnotationAttribute.java
private static TypeAnnotation parse(DataInputStream data, ConstantPool pool) throws IOException {
    int targetType = data.readUnsignedByte();
    int target = targetType << 24;

    switch (targetType) {
        case TypeAnnotation.CLASS_TYPE_PARAMETER:
        case TypeAnnotation.METHOD_TYPE_PARAMETER:
        case TypeAnnotation.METHOD_PARAMETER:
            target |= data.readUnsignedByte();
            break;

        case TypeAnnotation.SUPER_TYPE_REFERENCE:
        case TypeAnnotation.CLASS_TYPE_PARAMETER_BOUND:
        case TypeAnnotation.METHOD_TYPE_PARAMETER_BOUND:
        case TypeAnnotation.THROWS_REFERENCE:
        case TypeAnnotation.CATCH_CLAUSE:
        case TypeAnnotation.EXPR_INSTANCEOF:
        case TypeAnnotation.EXPR_NEW:
        case TypeAnnotation.EXPR_CONSTRUCTOR_REF:
        case TypeAnnotation.EXPR_METHOD_REF:
            target |= data.readUnsignedShort();
            break;

        case TypeAnnotation.TYPE_ARG_CAST:
        case TypeAnnotation.TYPE_ARG_CONSTRUCTOR_CALL:
        case TypeAnnotation.TYPE_ARG_METHOD_CALL:
        case TypeAnnotation.TYPE_ARG_CONSTRUCTOR_REF:
        case TypeAnnotation.TYPE_ARG_METHOD_REF:
            data.skipBytes(3);
            break;

        case TypeAnnotation.LOCAL_VARIABLE:
        case TypeAnnotation.RESOURCE_VARIABLE:
            data.skipBytes(data.readUnsignedShort() * 6);
            break;

        case TypeAnnotation.FIELD:
        case TypeAnnotation.METHOD_RETURN_TYPE:
        case TypeAnnotation.METHOD_RECEIVER:
            break;

        default:
            throw new RuntimeException("unknown target type: " + targetType);
    }

    int pathLength = data.readUnsignedByte();
    byte[] path = null;
    if (pathLength > 0) {
        path = new byte[2 * pathLength];
        data.readFully(path);
    }

    AnnotationExprent annotation = StructAnnotationAttribute.parseAnnotation(data, pool);

    return new TypeAnnotation(target, path, annotation);
}
 
源代码12 项目: j-j-jvm   文件: JJJVMConstantPoolImpl.java
public JJJVMConstantPoolImpl(final JJJVMClass klazz, final DataInputStream inStream) throws IOException {
  int index = 0;

  this.klazz = klazz;

  int itemsNumber = inStream.readUnsignedShort();
  this.records = new JJJVMConstantPoolItem[itemsNumber];
  this.records[index++] = null;
  itemsNumber--;

  final StringBuilder strBuffer = new StringBuilder(128);

  while (itemsNumber > 0) {
    boolean doubleRecordItem = false;
    final int recordType = inStream.readUnsignedByte();
    final Object recordValue;
    switch (recordType) {
      case JJJVMConstantPoolItem.CONSTANT_UTF8: {
        recordValue = inStream.readUTF();
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_UNICODE: {
        final int len = inStream.readUnsignedShort();
        for (int i = 0; i < len; i++) {
          char ch_char = (char) inStream.readUnsignedShort();
          strBuffer.append(ch_char);
        }
        recordValue = strBuffer.toString();
        strBuffer.setLength(0);
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_INTEGER: {
        recordValue = inStream.readInt();
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_FLOAT: {
        recordValue = inStream.readFloat();
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_LONG: {
        recordValue = inStream.readLong();
        doubleRecordItem = true;
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_DOUBLE: {
        recordValue = inStream.readDouble();
        doubleRecordItem = true;
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_CLASSREF:
      case JJJVMConstantPoolItem.CONSTANT_STRING: {
        recordValue = inStream.readUnsignedShort();
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_FIELDREF:
      case JJJVMConstantPoolItem.CONSTANT_METHODREF:
      case JJJVMConstantPoolItem.CONSTANT_INTERFACEMETHOD:
      case JJJVMConstantPoolItem.CONSTANT_NAMETYPEREF:
      case JJJVMConstantPoolItem.CONSTANT_METHODHANDLE:
      case JJJVMConstantPoolItem.CONSTANT_INVOKEDYNAMIC: {
        final int high = inStream.readUnsignedShort();
        final int low = inStream.readUnsignedShort();
        recordValue = (high << 16) | low;
      }
      break;
      case JJJVMConstantPoolItem.CONSTANT_METHODTYPE: {
        final int descIndex = inStream.readUnsignedShort();
        recordValue = descIndex;
      }
      break;
      default: {
        throw new IOException("Unsupported constant pool item [" + recordType + ']');
      }
    }

    this.records[index++] = new JJJVMConstantPoolItem(this, recordType, recordValue);
    if (doubleRecordItem) {
      itemsNumber--;
      index++;
    }
    itemsNumber--;
  }
}
 
/**
 * Reads the SIZ marker segment and realigns the codestream at the point
 * where the next marker segment should be found. 
 *
 * <p>SIZ is a fixed information marker segment containing informations
 * about image and tile sizes. It is required in the main header
 * immediately after SOC.</p>
 *
 * @param ehs The encoded header stream
 *
 * @exception IOException If an I/O error occurs while reading from the
 * encoded header stream
 * */
private void readSIZ (DataInputStream ehs) throws IOException {
    HeaderInfo.SIZ ms = hi.getNewSIZ();
    hi.siz = ms;

    // Read the length of SIZ marker segment (Lsiz)
    ms.lsiz = ehs.readUnsignedShort();

    // Read the capability of the codestream (Rsiz)
    ms.rsiz = ehs.readUnsignedShort();
    if (ms.rsiz > 2) {
        throw new Error("Codestream capabiities not JPEG 2000 - Part I"+
                        " compliant");
    }

    // Read image size
    ms.xsiz = ehs.readInt();
    ms.ysiz = ehs.readInt();
    if ( ms.xsiz<=0 || ms.ysiz<=0 ) {
        throw new IOException("JJ2000 does not support images whose "+
                              "width and/or height not in the "+
                              "range: 1 -- (2^31)-1");
    }

    // Read image offset
    ms.x0siz = ehs.readInt();
    ms.y0siz = ehs.readInt();
    if ( ms.x0siz<0 || ms.y0siz<0 ) {
        throw new IOException("JJ2000 does not support images offset "+
                              "not in the range: 0 -- (2^31)-1");
    }

    // Read size of tile
    ms.xtsiz = ehs.readInt();
    ms.ytsiz = ehs.readInt();
    if ( ms.xtsiz<=0 || ms.ytsiz<=0 ) {
        throw new IOException("JJ2000 does not support tiles whose "+
                              "width and/or height are not in  "+
                              "the range: 1 -- (2^31)-1");
    }

    // Read upper-left tile offset
    ms.xt0siz = ehs.readInt();
    ms.yt0siz = ehs.readInt();
    if ( ms.xt0siz<0 || ms.yt0siz<0 ){
        throw new IOException("JJ2000 does not support tiles whose "+
                              "offset is not in  "+
                              "the range: 0 -- (2^31)-1");
    }

    // Read number of components and initialize related arrays
    nComp = ms.csiz = ehs.readUnsignedShort();
    if (nComp<1 || nComp>16384) {
        throw new IllegalArgumentException("Number of component out of "+
                                           "range 1--16384: "+nComp);
    }

    ms.ssiz = new int[nComp];
    ms.xrsiz = new int[nComp];
    ms.yrsiz = new int[nComp];

    // Read bit-depth and down-sampling factors of each component
    for(int i = 0; i<nComp; i++) {
        ms.ssiz[i] = ehs.readUnsignedByte();
        ms.xrsiz[i] = ehs.readUnsignedByte();
        ms.yrsiz[i] = ehs.readUnsignedByte();
    }

    // Check marker length
    checkMarkerLength(ehs,"SIZ marker");

    // Create needed ModuleSpec
    nTiles = ms.getNumTiles();

    // Finish initialization of decSpec
    decSpec = new DecoderSpecs(nTiles,nComp);
}
 
源代码14 项目: j60870   文件: IeNameOfFile.java
static IeNameOfFile decode(DataInputStream is) throws IOException {
    int value = is.readUnsignedByte() | (is.readUnsignedByte() << 8);
    return new IeNameOfFile(value);
}
 
源代码15 项目: j60870   文件: IeAbstractQuality.java
IeAbstractQuality(DataInputStream is) throws IOException {
    value = is.readUnsignedByte();
}
 
private static TypeAnnotation parse(DataInputStream data, ConstantPool pool) throws IOException {
  int targetType = data.readUnsignedByte();
  int target = targetType << 24;

  switch (targetType) {
  case TypeAnnotation.CLASS_TYPE_PARAMETER:
  case TypeAnnotation.METHOD_TYPE_PARAMETER:
  case TypeAnnotation.METHOD_PARAMETER:
    target |= data.readUnsignedByte();
    break;

  case TypeAnnotation.SUPER_TYPE_REFERENCE:
  case TypeAnnotation.CLASS_TYPE_PARAMETER_BOUND:
  case TypeAnnotation.METHOD_TYPE_PARAMETER_BOUND:
  case TypeAnnotation.THROWS_REFERENCE:
  case TypeAnnotation.CATCH_CLAUSE:
  case TypeAnnotation.EXPR_INSTANCEOF:
  case TypeAnnotation.EXPR_NEW:
  case TypeAnnotation.EXPR_CONSTRUCTOR_REF:
  case TypeAnnotation.EXPR_METHOD_REF:
    target |= data.readUnsignedShort();
    break;

  case TypeAnnotation.TYPE_ARG_CAST:
  case TypeAnnotation.TYPE_ARG_CONSTRUCTOR_CALL:
  case TypeAnnotation.TYPE_ARG_METHOD_CALL:
  case TypeAnnotation.TYPE_ARG_CONSTRUCTOR_REF:
  case TypeAnnotation.TYPE_ARG_METHOD_REF:
    data.skipBytes(3);
    break;

  case TypeAnnotation.LOCAL_VARIABLE:
  case TypeAnnotation.RESOURCE_VARIABLE:
    data.skipBytes(data.readUnsignedShort() * 6);
    break;

  case TypeAnnotation.FIELD:
  case TypeAnnotation.METHOD_RETURN_TYPE:
  case TypeAnnotation.METHOD_RECEIVER:
    break;

  default:
    throw new RuntimeException("unknown target type: " + targetType);
  }

  int pathLength = data.readUnsignedByte();
  byte[] path = null;
  if (pathLength > 0) {
    path = new byte[2 * pathLength];
    data.readFully(path);
  }

  AnnotationExprent annotation = StructAnnotationAttribute.parseAnnotation(data, pool);

  return new TypeAnnotation(target, path, annotation);
}
 
源代码17 项目: jmg   文件: CPres.java
public int read(DataInputStream dis) throws IOException{
	this.pressure = (short) dis.readUnsignedByte();
	return 1;
}
 
源代码18 项目: openjdk-jdk9   文件: StringSharingPlugin.java
@SuppressWarnings("fallthrough")
private byte[] optimize(ResourcePoolEntry resource, ResourcePoolBuilder resources,
        StringTable strings,
        Set<Integer> descriptorIndexes, byte[] content) throws Exception {
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(content));
    ByteArrayOutputStream outStream = new ByteArrayOutputStream(content.length);
    DataOutputStream out = new DataOutputStream(outStream);
    byte[] header = new byte[8]; //magic/4, minor/2, major/2
    stream.readFully(header);
    out.write(header);
    int count = stream.readUnsignedShort();
    out.writeShort(count);
    for (int i = 1; i < count; i++) {
        int tag = stream.readUnsignedByte();
        byte[] arr;
        switch (tag) {
            case ConstantPool.CONSTANT_Utf8: {
                String original = stream.readUTF();
                // 2 cases, a Descriptor or a simple String
                if (descriptorIndexes.contains(i)) {
                    SignatureParser.ParseResult parseResult
                            = SignatureParser.parseSignatureDescriptor(original);
                    List<Integer> indexes
                            = parseResult.types.stream().map((type) -> {
                                return strings.addString(type);
                            }).collect(Collectors.toList());
                    if (!indexes.isEmpty()) {
                        out.write(StringSharingDecompressor.EXTERNALIZED_STRING_DESCRIPTOR);
                        int sigIndex = strings.addString(parseResult.formatted);
                        byte[] compressed
                                = CompressIndexes.compress(sigIndex);
                        out.write(compressed, 0, compressed.length);

                        writeDescriptorReference(out, indexes);
                        continue;
                    }
                }
                // Put all strings in strings table.
                writeUTF8Reference(out, strings.addString(original));

                break;
            }

            case ConstantPool.CONSTANT_Long:
            case ConstantPool.CONSTANT_Double: {
                i++;
            }
            default: {
                out.write(tag);
                int size = SIZES[tag];
                arr = new byte[size];
                stream.readFully(arr);
                out.write(arr);
            }
        }
    }
    out.write(content, content.length - stream.available(),
            stream.available());
    out.flush();

    return outStream.toByteArray();
}
 
源代码19 项目: LocalGSMLocationProvider   文件: IndexHash.java
public void validate(InputStream in) throws IOException {
    // Index Indicator (0x00) has already been read by BlockInputStream
    // so add 0x00 to the CRC32 here.
    java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
    crc32.update('\0');
    CheckedInputStream inChecked = new CheckedInputStream(in, crc32);

    // Get and validate the Number of Records field.
    long storedRecordCount = DecoderUtil.decodeVLI(inChecked);
    if (storedRecordCount != recordCount)
        throw new CorruptedInputException("XZ Index is corrupt");

    // Decode and hash the Index field and compare it to
    // the hash value calculated from the decoded Blocks.
    IndexHash stored = new IndexHash();
    for (long i = 0; i < recordCount; ++i) {
        long unpaddedSize = DecoderUtil.decodeVLI(inChecked);
        long uncompressedSize = DecoderUtil.decodeVLI(inChecked);

        try {
            stored.add(unpaddedSize, uncompressedSize);
        } catch (XZIOException e) {
            throw new CorruptedInputException("XZ Index is corrupt");
        }

        if (stored.blocksSum > blocksSum
                || stored.uncompressedSum > uncompressedSum
                || stored.indexListSize > indexListSize)
            throw new CorruptedInputException("XZ Index is corrupt");
    }

    if (stored.blocksSum != blocksSum
            || stored.uncompressedSum != uncompressedSum
            || stored.indexListSize != indexListSize
            || !Arrays.equals(stored.hash.finish(), hash.finish()))
        throw new CorruptedInputException("XZ Index is corrupt");

    // Index Padding
    DataInputStream inData = new DataInputStream(inChecked);
    for (int i = getIndexPaddingSize(); i > 0; --i)
        if (inData.readUnsignedByte() != 0x00)
            throw new CorruptedInputException("XZ Index is corrupt");

    // CRC32
    long value = crc32.getValue();
    for (int i = 0; i < 4; ++i)
        if (((value >>> (i * 8)) & 0xFF) != inData.readUnsignedByte())
            throw new CorruptedInputException("XZ Index is corrupt");
}
 
源代码20 项目: j60870   文件: IeNameOfSection.java
static IeNameOfSection decode(DataInputStream is) throws IOException {
    return new IeNameOfSection(is.readUnsignedByte());
}