Beispiel #1
0
 public void a(DataInput datainput) {
   this.e = datainput.readUnsignedByte();
   this.a = datainput.readInt();
   this.b = datainput.readUnsignedByte();
   this.c = datainput.readInt();
   this.face = datainput.readUnsignedByte();
 }
Beispiel #2
0
  public static final void copyString(DataInput in, DataOutput out) throws IOException {
    int len = in.readUnsignedByte();
    out.writeByte(len);

    if (len >= HIGH_BIT) {
      int shift = 7;
      int curr;
      len = len & 0x7f;
      while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
        out.writeByte(curr);
        len |= (curr & 0x7f) << shift;
        shift += 7;
      }
      out.writeByte(curr);
      len |= curr << shift;
    }

    // note that the length is one larger than the actual length (length 0 is a null string, not a
    // zero length string)
    len--;

    for (int i = 0; i < len; i++) {
      int c = in.readUnsignedByte();
      out.writeByte(c);
      while (c >= HIGH_BIT) {
        c = in.readUnsignedByte();
        out.writeByte(c);
      }
    }
  }
 public void readFrom(DataInput din) throws IOException {
   if (!isHeadless()) {
     setTransactionID(din.readUnsignedShort());
     setProtocolID(din.readUnsignedShort());
     m_DataLength = din.readUnsignedShort();
   }
   setUnitID(din.readUnsignedByte());
   setFunctionCode(din.readUnsignedByte());
   readData(din);
 } // readFrom
Beispiel #4
0
 /**
  * Reads in a string from the specified data input stream. The string has been encoded using a
  * modified UTF-8 format.
  *
  * <p>The first two bytes are read as if by <code>readUnsignedShort</code>. This value gives the
  * number of following bytes that are in the encoded string, not the length of the resulting
  * string. The following bytes are then interpreted as bytes encoding characters in the UTF-8
  * format and are converted into characters.
  *
  * <p>This method blocks until all the bytes are read, the end of the stream is detected, or an
  * exception is thrown.
  *
  * @param in a data input stream.
  * @return a Unicode string.
  * @exception EOFException if the input stream reaches the end before all the bytes.
  * @exception IOException if an I/O error occurs.
  * @exception UTFDataFormatException if the bytes do not represent a valid UTF-8 encoding of a
  *     Unicode string.
  * @see java.io.DataInputStream#readUnsignedShort()
  */
 public static final char[] readUTF(DataInput in) throws IOException {
   int utflen = in.readUnsignedShort();
   char str[] = new char[utflen];
   int count = 0;
   int strlen = 0;
   while (count < utflen) {
     int c = in.readUnsignedByte();
     int char2, char3;
     switch (c >> 4) {
       case 0:
       case 1:
       case 2:
       case 3:
       case 4:
       case 5:
       case 6:
       case 7:
         // 0xxxxxxx
         count++;
         str[strlen++] = (char) c;
         break;
       case 12:
       case 13:
         // 110x xxxx   10xx xxxx
         count += 2;
         if (count > utflen) throw new UTFDataFormatException();
         char2 = in.readUnsignedByte();
         if ((char2 & 0xC0) != 0x80) throw new UTFDataFormatException();
         str[strlen++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
         break;
       case 14:
         // 1110 xxxx  10xx xxxx  10xx xxxx
         count += 3;
         if (count > utflen) throw new UTFDataFormatException();
         char2 = in.readUnsignedByte();
         char3 = in.readUnsignedByte();
         if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
           throw new UTFDataFormatException();
         str[strlen++] =
             (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
         break;
       default:
         // 10xx xxxx,  1111 xxxx
         throw new UTFDataFormatException();
     }
   }
   if (strlen < utflen) {
     System.arraycopy(str, 0, str = new char[strlen], 0, strlen);
   }
   return str;
 }
  /**
   * Read a long previously written by writeLong().
   *
   * @exception IOException an exception was thrown by a method on in.
   */
  public static final long readLong(DataInput in) throws IOException {

    int int_value = in.readUnsignedByte();

    if ((int_value & ~0x3f) == 0) {
      // test for small case first - assuming this is usual case.
      // this is stored in 2 bytes.

      return ((int_value << 8) | in.readUnsignedByte());
    } else if ((int_value & 0x80) == 0) {
      // value is stored in 4 bytes.  only use low 6 bits from 1st byte.

      return (((int_value & 0x3f) << 24)
          | (in.readUnsignedByte() << 16)
          | (in.readUnsignedByte() << 8)
          | (in.readUnsignedByte()));
    } else {
      // value is stored in 8 bytes.  only use low 7 bits from 1st byte.
      return ((((long) (int_value & 0x7f)) << 56)
          | (((long) in.readUnsignedByte()) << 48)
          | (((long) in.readUnsignedByte()) << 40)
          | (((long) in.readUnsignedByte()) << 32)
          | (((long) in.readUnsignedByte()) << 24)
          | (((long) in.readUnsignedByte()) << 16)
          | (((long) in.readUnsignedByte()) << 8)
          | (((long) in.readUnsignedByte())));
    }
  }
Beispiel #6
0
 public InodeEntry readData(DataInput in) throws Exception {
   if (length != null) {
     byte[] buf = new byte[getReadSize()];
     in.readFully(buf);
     name = new String(buf);
     int i = name.indexOf('\0');
     if (i >= 0) name = name.substring(0, i);
   } else {
     fsid = Utils.getUnsigned(in.readInt());
     length = in.readUnsignedByte();
     type = InodeType.fromInt(in.readUnsignedByte());
   }
   return this;
 }
Beispiel #7
0
  /** Creates new PostTable */
  protected PostTable(final DirectoryEntry de, final DataInput di) throws IOException {
    this.de = (DirectoryEntry) de.clone();
    version = di.readInt();
    italicAngle = di.readInt();
    underlinePosition = di.readShort();
    underlineThickness = di.readShort();
    isFixedPitch = di.readInt();
    minMemType42 = di.readInt();
    maxMemType42 = di.readInt();
    minMemType1 = di.readInt();
    maxMemType1 = di.readInt();

    if (version == 0x00020000) {
      numGlyphs = di.readUnsignedShort();
      glyphNameIndex = new int[numGlyphs];
      for (int i = 0; i < numGlyphs; i++) {
        glyphNameIndex[i] = di.readUnsignedShort();
      }
      int h = highestGlyphNameIndex();
      if (h > 257) {
        h -= 257;
        psGlyphName = new String[h];
        for (int i = 0; i < h; i++) {
          final int len = di.readUnsignedByte();
          final byte[] buf = new byte[len];
          di.readFully(buf);
          psGlyphName[i] = new String(buf);
        }
      }
      // } else if (version == 0x00025000) {
      // } else if (version == 0x00030000) {
    }
  }
Beispiel #8
0
  private static Node deserializeNode(DataInput input) throws IOException {
    int level = input.readUnsignedByte();
    long value = input.readLong();
    double weight = input.readDouble();

    return new Node(value, level, weight);
  }
  /** Return {@code true} if a double slot is read (in case of Double or Long constant). */
  private boolean readConstantPoolEntry(final DataInput di, final int index) throws IOException {

    final int tag = di.readUnsignedByte();
    switch (tag) {
      case CP_METHOD_TYPE:
        di.skipBytes(2); // readUnsignedShort()
        return false;
      case CP_METHOD_HANDLE:
        di.skipBytes(3);
        return false;
      case CP_INTEGER:
      case CP_FLOAT:
      case CP_REF_FIELD:
      case CP_REF_METHOD:
      case CP_REF_INTERFACE:
      case CP_NAME_AND_TYPE:
      case CP_INVOKE_DYNAMIC:
        di.skipBytes(4); // readInt() / readFloat() / readUnsignedShort() * 2
        return false;
      case CP_LONG:
      case CP_DOUBLE:
        di.skipBytes(8); // readLong() / readDouble()
        return true;
      case CP_UTF8:
        constantPool[index] = di.readUTF();
        return false;
      case CP_CLASS:
      case CP_STRING:
        // reference to CP_UTF8 entry. The referenced index can have a higher number!
        constantPool[index] = di.readUnsignedShort();
        return false;
      default:
        throw new ClassFormatError("Unkown tag value for constant pool entry: " + tag);
    }
  }
Beispiel #10
0
 @Override
 public int readUnsignedByte() {
   try {
     return input.readUnsignedByte();
   } catch (IOException e) {
     throw new IllegalStateException(e);
   }
 }
  /**
   * Read an integer previously written by writeInt().
   *
   * @exception IOException an exception was thrown by a method on in.
   */
  public static final int readInt(DataInput in) throws IOException {

    int value = in.readUnsignedByte();

    if ((value & ~0x3f) == 0) {
      // length is stored in this byte, we also know that the 0x80 bit
      // was not set, so no need to mask off the sign extension from
      // the byte to int conversion.

      // account for 1 byte stored length of field + 1 for all returns
      return (value);
    } else if ((value & 0x80) == 0) {
      // length is stored in 2 bytes.  only use low 6 bits from 1st byte.

      if (SanityManager.DEBUG) {
        SanityManager.ASSERT((value & 0x40) == 0x40);
      }

      // top 8 bits of 2 byte length is stored in this byte, we also
      // know that the 0x80 bit was not set, so no need to mask off the
      // sign extension from the 1st byte to int conversion.  Need to
      // mask the byte in data[offset + 1] to account for possible sign
      // extension.

      return (((value & 0x3f) << 8) | in.readUnsignedByte());
    } else {
      // length is stored in 4 bytes.  only use low 7 bits from 1st byte.

      if (SanityManager.DEBUG) {
        SanityManager.ASSERT((value & 0x80) == 0x80);
      }

      // top 8 bits of 4 byte length is stored in this byte, we also
      // know that the 0x80 bit was set, so need to mask off the
      // sign extension from the 1st byte to int conversion.  Need to
      // mask the bytes from the next 3 bytes data[offset + 1,2,3] to
      // account for possible sign extension.
      //
      return (((value & 0x7f) << 24)
          | (in.readUnsignedByte() << 16)
          | (in.readUnsignedByte() << 8)
          | (in.readUnsignedByte()));
    }
  }
Beispiel #12
0
  public static String readString(DataInput in) throws IOException {
    // the length we read is offset by one, because a length of zero indicates a null value
    int len = in.readUnsignedByte();

    if (len == 0) {
      return null;
    }

    if (len >= HIGH_BIT) {
      int shift = 7;
      int curr;
      len = len & 0x7f;
      while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
        len |= (curr & 0x7f) << shift;
        shift += 7;
      }
      len |= curr << shift;
    }

    // subtract one for the null length
    len -= 1;

    final char[] data = new char[len];

    for (int i = 0; i < len; i++) {
      int c = in.readUnsignedByte();
      if (c < HIGH_BIT) {
        data[i] = (char) c;
      } else {
        int shift = 7;
        int curr;
        c = c & 0x7f;
        while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
          c |= (curr & 0x7f) << shift;
          shift += 7;
        }
        c |= curr << shift;
        data[i] = (char) c;
      }
    }

    return new String(data, 0, len);
  }
  MethodParameters(int name_index, int length, DataInput input, ConstantPool constant_pool)
      throws IOException {
    super(Constants.ATTR_METHOD_PARAMETERS, name_index, length, constant_pool);
    System.out.println("new MethodParameters");

    int parameters_count = input.readUnsignedByte();
    parameters = new MethodParameter[parameters_count];
    for (int i = 0; i < parameters_count; i++) {
      parameters[i] = new MethodParameter(input);
    }
  }
Beispiel #14
0
    static String readPascalString(final DataInput pInput) throws IOException {
      int length = pInput.readUnsignedByte();

      if (length == 0) {
        return "";
      }

      byte[] bytes = new byte[length];
      pInput.readFully(bytes);

      return StringUtil.decode(bytes, 0, bytes.length, "ASCII");
    }
 public UnsignedByteArray(DataInput in, int length) throws IOException {
   if (length == -1) {
     throw new RuntimeException("variable length " + getClass() + " not implemented");
   } else {
     this.length = length;
     data = new short[length];
     for (int i = 0; i < length; i++) {
       data[i] = (short) in.readUnsignedByte();
     }
     this.offset = 0;
   }
 }
  public void readData(DataInput din) throws IOException {
    setByteCount(din.readUnsignedByte());

    InputRegister[] registers = new InputRegister[getWordCount()];
    ProcessImageFactory pimf = ModbusCoupler.getReference().getProcessImageFactory();
    for (int k = 0; k < getWordCount(); k++) {
      registers[k] = pimf.createInputRegister(din.readByte(), din.readByte());
    }
    m_Registers = registers;
    // update data length
    setDataLength(getByteCount() + 1);
  } // readData
  public void read(DataInput in) throws InvalidByteCodeException, IOException {

    int numberOfEntries = in.readUnsignedByte();
    entries = new MethodParametersEntry[numberOfEntries];

    for (int i = 0; i < numberOfEntries; i++) {
      entries[i] = MethodParametersEntry.create(in, classFile);
    }

    if (debug) {
      debug("read ");
    }
  }
  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);
    }
  } // readData
 private static AbstractConfigValue readValueData(DataInput in, SimpleConfigOrigin origin)
     throws IOException {
   int stb = in.readUnsignedByte();
   SerializedValueType st = SerializedValueType.forInt(stb);
   if (st == null) throw new IOException("Unknown serialized value type: " + stb);
   switch (st) {
     case BOOLEAN:
       return new ConfigBoolean(origin, in.readBoolean());
     case NULL:
       return new ConfigNull(origin);
     case INT:
       int vi = in.readInt();
       String si = in.readUTF();
       return new ConfigInt(origin, vi, si);
     case LONG:
       long vl = in.readLong();
       String sl = in.readUTF();
       return new ConfigLong(origin, vl, sl);
     case DOUBLE:
       double vd = in.readDouble();
       String sd = in.readUTF();
       return new ConfigDouble(origin, vd, sd);
     case STRING:
       return new ConfigString.Quoted(origin, in.readUTF());
     case LIST:
       int listSize = in.readInt();
       List<AbstractConfigValue> list = new ArrayList<AbstractConfigValue>(listSize);
       for (int i = 0; i < listSize; ++i) {
         AbstractConfigValue v = readValue(in, origin);
         list.add(v);
       }
       return new SimpleConfigList(origin, list);
     case OBJECT:
       int mapSize = in.readInt();
       Map<String, AbstractConfigValue> map = new HashMap<String, AbstractConfigValue>(mapSize);
       for (int i = 0; i < mapSize; ++i) {
         String key = in.readUTF();
         AbstractConfigValue v = readValue(in, origin);
         map.put(key, v);
       }
       return new SimpleConfigObject(origin, map);
   }
   throw new IOException("Unhandled serialized value type: " + st);
 }
Beispiel #20
0
  public static RNASequence readRNASequence(DataInput in) throws IOException {
    int size = in.readInt();
    char[] chars = new char[size];

    int completed = 0;
    while (completed < size) {
      int value = in.readUnsignedByte();
      chars[completed++] = getUnserializedRNABase((value >> 6));
      if (completed < size) {
        chars[completed++] = getUnserializedRNABase(((value >> 4) - ((value >> 6) << 2)));
      }
      if (completed < size) {
        chars[completed++] = getUnserializedRNABase(((value >> 2) - ((value >> 4) << 2)));
      }
      if (completed < size) {
        chars[completed++] = getUnserializedRNABase(((value) - ((value >> 2) << 2)));
      }
    }

    return new RNASequence(new String(chars));
  }
 private void readAnnotationElementValue(final DataInput di) throws IOException {
   final int tag = di.readUnsignedByte();
   if (DEBUG) {
     print("tag='%c'", (char) tag);
   }
   switch (tag) {
     case BYTE:
     case CHAR:
     case DOUBLE:
     case FLOAT:
     case INT:
     case LONG:
     case SHORT:
     case BOOLEAN:
     case STRING:
       di.skipBytes(2);
       break;
     case ENUM:
       di.skipBytes(4); // 2 * u2
       break;
     case CLASS:
       di.skipBytes(2);
       break;
     case ANNOTATION:
       readAnnotation(di);
       break;
     case ARRAY:
       final int count = di.readUnsignedShort();
       for (int i = 0; i < count; ++i) {
         readAnnotationElementValue(di);
       }
       break;
     default:
       throw new ClassFormatError(
           "Not a valid annotation element type tag: 0x" + Integer.toHexString(tag));
   }
 }
 private static SerializedField readCode(DataInput in) throws IOException {
   int c = in.readUnsignedByte();
   if (c == SerializedField.UNKNOWN.ordinal())
     throw new IOException("field code " + c + " is not supposed to be on the wire");
   return SerializedField.forInt(c);
 }
 // not private because we use it to deserialize ConfigException
 static SimpleConfigOrigin readOrigin(DataInput in, SimpleConfigOrigin baseOrigin)
     throws IOException {
   Map<SerializedField, Object> m = new EnumMap<SerializedField, Object>(SerializedField.class);
   while (true) {
     Object v = null;
     SerializedField field = readCode(in);
     switch (field) {
       case END_MARKER:
         return SimpleConfigOrigin.fromBase(baseOrigin, m);
       case ORIGIN_DESCRIPTION:
         in.readInt(); // discard length
         v = in.readUTF();
         break;
       case ORIGIN_LINE_NUMBER:
         in.readInt(); // discard length
         v = in.readInt();
         break;
       case ORIGIN_END_LINE_NUMBER:
         in.readInt(); // discard length
         v = in.readInt();
         break;
       case ORIGIN_TYPE:
         in.readInt(); // discard length
         v = in.readUnsignedByte();
         break;
       case ORIGIN_URL:
         in.readInt(); // discard length
         v = in.readUTF();
         break;
       case ORIGIN_RESOURCE:
         in.readInt(); // discard length
         v = in.readUTF();
         break;
       case ORIGIN_COMMENTS:
         in.readInt(); // discard length
         int size = in.readInt();
         List<String> list = new ArrayList<String>(size);
         for (int i = 0; i < size; ++i) {
           list.add(in.readUTF());
         }
         v = list;
         break;
       case ORIGIN_NULL_URL: // FALL THRU
       case ORIGIN_NULL_RESOURCE: // FALL THRU
       case ORIGIN_NULL_COMMENTS:
         // nothing to read besides code and length
         in.readInt(); // discard length
         v = ""; // just something non-null to put in the map
         break;
       case ROOT_VALUE:
       case ROOT_WAS_CONFIG:
       case VALUE_DATA:
       case VALUE_ORIGIN:
         throw new IOException("Not expecting this field here: " + field);
       case UNKNOWN:
         // skip unknown field
         skipField(in);
         break;
     }
     if (v != null) m.put(field, v);
   }
 }
  public static NiftiHeader read(String fn) throws IOException {
    DataInput di;

    boolean le = littleEndian(fn);

    InputStream is = new FileInputStream(fn);
    if (fn.endsWith(".gz")) is = new GZIPInputStream(is);

    if (le) di = new LEDataInputStream(is);
    else di = new DataInputStream(is);

    NiftiHeader ds = new NiftiHeader();

    ds.filename = fn;
    ds.little_endian = le;
    ds.sizeof_hdr = di.readInt();

    byte[] bb = new byte[10];
    di.readFully(bb, 0, 10);
    ds.data_type_string = new StringBuffer(new String(bb));

    bb = new byte[18];
    di.readFully(bb, 0, 18);
    ds.db_name = new StringBuffer(new String(bb));
    ds.extents = di.readInt();
    ds.session_error = di.readShort();
    ds.regular = new StringBuffer();
    ds.regular.append((char) (di.readUnsignedByte()));
    ds.dim_info = new StringBuffer();
    ds.dim_info.append((char) (di.readUnsignedByte()));

    int fps_dim = (int) ds.dim_info.charAt(0);
    ds.freq_dim = (short) (fps_dim & 3);
    ds.phase_dim = (short) ((fps_dim >>> 2) & 3);
    ds.slice_dim = (short) ((fps_dim >>> 4) & 3);

    for (int i = 0; i < 8; i++) ds.dim[i] = di.readShort();
    if (ds.dim[0] > 0) ds.dim[1] = ds.dim[1];
    if (ds.dim[0] > 1) ds.dim[2] = ds.dim[2];
    if (ds.dim[0] > 2) ds.dim[3] = ds.dim[3];
    if (ds.dim[0] > 3) ds.dim[4] = ds.dim[4];

    for (int i = 0; i < 3; i++) ds.intent[i] = di.readFloat();

    ds.intent_code = di.readShort();
    ds.datatype = di.readShort();
    ds.bitpix = di.readShort();
    ds.slice_start = di.readShort();

    for (int i = 0; i < 8; i++) ds.pixdim[i] = di.readFloat();

    ds.qfac = (short) Math.floor((double) (ds.pixdim[0]));
    ds.vox_offset = di.readFloat();
    ds.scl_slope = di.readFloat();
    ds.scl_inter = di.readFloat();
    ds.slice_end = di.readShort();
    ds.slice_code = (byte) di.readUnsignedByte();

    ds.xyzt_units = (byte) di.readUnsignedByte();

    int unit_codes = (int) ds.xyzt_units;
    ds.xyz_unit_code = (short) (unit_codes & 007);
    ds.t_unit_code = (short) (unit_codes & 070);

    ds.cal_max = di.readFloat();
    ds.cal_min = di.readFloat();
    ds.slice_duration = di.readFloat();
    ds.toffset = di.readFloat();
    ds.glmax = di.readInt();
    ds.glmin = di.readInt();

    bb = new byte[80];
    di.readFully(bb, 0, 80);
    ds.descrip = new StringBuffer(new String(bb));

    bb = new byte[24];
    di.readFully(bb, 0, 24);
    ds.aux_file = new StringBuffer(new String(bb));

    ds.qform_code = di.readShort();
    ds.sform_code = di.readShort();

    for (int i = 0; i < 3; i++) ds.quatern[i] = di.readFloat();
    for (int i = 0; i < 3; i++) ds.qoffset[i] = di.readFloat();

    for (int i = 0; i < 4; i++) ds.srow_x[i] = di.readFloat();
    for (int i = 0; i < 4; i++) ds.srow_y[i] = di.readFloat();
    for (int i = 0; i < 4; i++) ds.srow_z[i] = di.readFloat();

    bb = new byte[16];
    di.readFully(bb, 0, 16);
    ds.intent_name = new StringBuffer(new String(bb));

    bb = new byte[4];
    di.readFully(bb, 0, 4);
    ds.magic = new StringBuffer(new String(bb));

    di.readFully(ds.extension, 0, 4);

    if (ds.extension[0] != (byte) 0) {
      int start_addr = NiftiHeader.ANZ_HDR_SIZE + 4;

      while (start_addr < (int) ds.vox_offset) {
        int[] size_code = new int[2];
        size_code[0] = di.readInt();
        size_code[1] = di.readInt();

        int nb = size_code[0] - NiftiHeader.EXT_KEY_SIZE;
        byte[] eblob = new byte[nb];
        di.readFully(eblob, 0, nb);
        ds.extension_blobs.add(eblob);
        ds.extensions_list.add(size_code);
        start_addr += (size_code[0]);

        if (start_addr > (int) ds.vox_offset)
          throw new IOException(
              "Error: Data  for extension "
                  + (ds.extensions_list.size())
                  + " appears to overrun start of image data.");
      }
    }

    return ds;
  }
Beispiel #25
0
 public int readUnsignedByte() throws IOException {
   return dataInput.readUnsignedByte();
 }
Beispiel #26
0
 protected void readPayload(final DataInput input) throws IOException {
   setTeamId(input.readUnsignedByte());
 }