Exemplo n.º 1
0
  @Override
  public void parseFromDataInput(DataInput read) throws IOException {
    this.buildVersion = read.readUTF();
    this.gameId = read.readInt();
    this.guid = read.readUTF();
    this.password = read.readUTF();
    secret = read.readUTF();
    keyTime = read.readInt();
    int size = read.readUnsignedShort();
    if (size > 0) {
      key = new byte[size];
      read.readFully(key);
    }

    size = read.readInt();
    if (size > 0) {
      byte[] buf = new byte[size];
      read.readFully(buf);
      unkStr = new String(buf, Charset.forName("UTF-8"));
    }

    pk = read.readUTF();
    Tq = read.readUTF();
    H = read.readUTF();
    playPlatform = read.readUTF();
  }
Exemplo n.º 2
0
  public final void readFields(DataInput in) throws IOException {
    metadata.clear();
    int sizeOrVersion = in.readInt();
    if (sizeOrVersion < 0) { // version
      version = sizeOrVersion;
      switch (version) {
        case VERSION:
          url = Text.readString(in);
          base = Text.readString(in);

          content = new byte[in.readInt()];
          in.readFully(content);

          contentType = Text.readString(in);
          metadata.readFields(in);
          break;
        default:
          throw new VersionMismatchException((byte) VERSION, (byte) version);
      }
    } else { // size
      byte[] compressed = new byte[sizeOrVersion];
      in.readFully(compressed, 0, compressed.length);
      ByteArrayInputStream deflated = new ByteArrayInputStream(compressed);
      DataInput inflater = new DataInputStream(new InflaterInputStream(deflated));
      readFieldsCompressed(inflater);
    }
  }
Exemplo n.º 3
0
 @Override
 public void readFields(DataInput dataInput) throws IOException {
   int length1 = dataInput.readInt();
   int length2 = dataInput.readInt();
   int s1Len = dataInput.readInt();
   int s2Len = dataInput.readInt();
   if (length1 > 0) {
     first = new byte[length1];
     dataInput.readFully(first);
   }
   if (length2 > 0) {
     second = new byte[length2];
     dataInput.readFully(second);
   }
   if (s1Len > 0) {
     byte[] s1Bytes = new byte[s1Len];
     dataInput.readFully(s1Bytes);
     uriFirst = new String(s1Bytes, Charset.forName("UTF-8"));
   }
   if (s2Len > 0) {
     byte[] s2Bytes = new byte[s2Len];
     dataInput.readFully(s2Bytes);
     uriSecond = new String(s2Bytes, Charset.forName("UTF-8"));
   }
 }
Exemplo n.º 4
0
  public void readFields(DataInput in) throws IOException {
    in.readFully(internalBytes, 0, 4);
    if (TimestampWritable.hasDecimalOrSecondVInt(internalBytes[0])) {
      in.readFully(internalBytes, 4, 1);
      int len = (byte) WritableUtils.decodeVIntSize(internalBytes[4]);
      if (len > 1) {
        in.readFully(internalBytes, 5, len - 1);
      }

      long vlong = LazyBinaryUtils.readVLongFromByteArray(internalBytes, 4);
      if (vlong < -1000000000 || vlong > 999999999) {
        throw new IOException(
            "Invalid first vint value (encoded nanoseconds) of a TimestampWritable: "
                + vlong
                + ", expected to be between -1000000000 and 999999999.");
        // Note that -1000000000 is a valid value corresponding to a nanosecond timestamp
        // of 999999999, because if the second VInt is present, we use the value
        // (-reversedNanoseconds - 1) as the second VInt.
      }
      if (vlong < 0) {
        // This indicates there is a second VInt containing the additional bits of the seconds
        // field.
        in.readFully(internalBytes, 4 + len, 1);
        int secondVIntLen = (byte) WritableUtils.decodeVIntSize(internalBytes[4 + len]);
        if (secondVIntLen > 1) {
          in.readFully(internalBytes, 5 + len, secondVIntLen - 1);
        }
      }
    }
    currentBytes = internalBytes;
    this.offset = 0;
  }
Exemplo n.º 5
0
    @Override
    public void readFields(DataInput dataInput) throws IOException {
      int len;
      byte[] buf;

      locations = new ArrayList<String>();
      length = dataInput.readLong();
      LOG.debug("Read length of " + length);
      int numElements = dataInput.readInt();
      LOG.debug("Read numElements of " + numElements);
      for (int i = 0; i < numElements; i++) {
        len = dataInput.readInt();
        LOG.debug("Read file length of " + len);
        buf = new byte[len];
        dataInput.readFully(buf);
        locations.add(new String(buf));
      }
      bucketNum = dataInput.readInt();
      LOG.debug("Read bucket number of " + bucketNum);
      len = dataInput.readInt();
      LOG.debug("Read base path length of " + len);
      if (len > 0) {
        buf = new byte[len];
        dataInput.readFully(buf);
        base = new Path(new String(buf));
      }
      numElements = dataInput.readInt();
      deltas = new Path[numElements];
      for (int i = 0; i < numElements; i++) {
        len = dataInput.readInt();
        buf = new byte[len];
        dataInput.readFully(buf);
        deltas[i] = new Path(new String(buf));
      }
    }
Exemplo n.º 6
0
  /**
   * Creates a new instance of MessagePackageHeader. Used for incoming messages.
   *
   * @param in The stream from which the headers will be read.
   * @throws java.io.IOException if an io error occurs.
   */
  public MessagePackageHeader(InputStream in) throws IOException {
    boolean sawEmpty = false;
    boolean sawLength = false;
    boolean sawType = false;
    DataInput di = new DataInputStream(in);

    // todo 20021014 [email protected] A framing signature would help here.

    do {
      byte headerNameLength = di.readByte();

      if (0 == headerNameLength) {
        sawEmpty = true;
      } else {
        byte[] headerNameBytes = new byte[headerNameLength];

        di.readFully(headerNameBytes);

        String headerNameString = new String(headerNameBytes, "UTF-8");

        if (headerNameString.equalsIgnoreCase(CONTENT_LENGTH)) {
          if (sawLength) {
            throw new IOException("Duplicate content-length header");
          }
          sawLength = true;
        }

        if (headerNameString.equalsIgnoreCase(CONTENT_TYPE)) {
          if (sawType) {
            throw new IOException("Duplicate content-type header");
          }
          sawType = true;
        }

        int headerValueLength = di.readUnsignedShort();

        byte[] headerValueBytes = new byte[headerValueLength];

        di.readFully(headerValueBytes);

        headers.add(new Header(headerNameString, headerValueBytes));
      }
    } while (!sawEmpty);

    if (!sawLength) {
      if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
        LOG.warning("Content Length header was missing");
      }
      throw new IOException("Content Length header was missing");
    }

    if (!sawType) {
      if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
        LOG.warning("Content Type header was missing");
      }
      throw new IOException("Content Type header was missing");
    }
  }
 @Override
 public void readFrom(DataInput in) throws IOException {
   commandName = in.readUTF();
   commandIdentifier = in.readUTF();
   expectReply = in.readBoolean();
   payloadType = in.readUTF();
   payloadRevision = in.readUTF();
   if ("_null".equals(payloadRevision)) {
     payloadRevision = null;
   }
   serializedPayload = new byte[in.readInt()];
   in.readFully(serializedPayload);
   serializedMetaData = new byte[in.readInt()];
   in.readFully(serializedMetaData);
 }
Exemplo n.º 8
0
  public void read(DataInput in) throws InvalidByteCodeException, IOException {

    info = new byte[attributeLength];
    in.readFully(info);

    if (debug) debug("read " + getDebugMessage());
  }
Exemplo n.º 9
0
 public RowCacheKey deserialize(DataInput dataInput) throws IOException {
   long msb = dataInput.readLong();
   long lsb = dataInput.readLong();
   byte[] key = new byte[dataInput.readInt()];
   dataInput.readFully(key);
   return new RowCacheKey(new UUID(msb, lsb), key);
 }
  /*
   * (non-Javadoc)
   * @see eu.stratosphere.core.io.IOReadableWritable#read(java.io.DataInput)
   */
  @Override
  public void read(final DataInput in) throws IOException {
    this.mode = ExecutionMode.values()[in.readInt()];

    final ArrayList<String> requiredPackages = new ArrayList<String>();
    for (int count = in.readInt(); count > 0; count--) requiredPackages.add(in.readUTF());
    this.query = null;
    final byte[] planBuffer = new byte[in.readInt()];
    in.readFully(planBuffer);

    final JobID dummId = new JobID();
    try {
      LibraryCacheManager.register(
          dummId, requiredPackages.toArray(new String[requiredPackages.size()]));
      SopremoEnvironment.getInstance().setClassLoader(LibraryCacheManager.getClassLoader(dummId));
      this.query = SopremoUtil.deserialize(planBuffer, SopremoPlan.class);
    } catch (final IOException e) {
      e.printStackTrace();
    } finally {
      try {
        LibraryCacheManager.unregister(dummId);
      } catch (final IOException e) {
      }
    }
  }
 public void readData(DataInput in) throws IOException {
   this.age = in.readInt();
   int size = in.readInt();
   byte[] bytes = new byte[size];
   in.readFully(bytes);
   this.name = new String(bytes);
 }
Exemplo n.º 12
0
 public void readFields(DataInput in) throws IOException {
   this.key = new byte[in.readInt()];
   in.readFully(key);
   this.createdTime = in.readLong();
   this.modifiedTime = in.readLong();
   this.state = in.readByte();
 }
  /**
   * Deserializes an {@link Serializable} from a {@link DataInput}.<br>
   * Please note that this method is not very efficient.
   */
  public static <T extends Serializable> T deserializeObject(DataInput in, Class<T> clazz)
      throws IOException {
    byte[] buffer = new byte[in.readInt()];
    in.readFully(buffer);

    return byteArrayToSerializable(buffer, clazz, clazz.getClassLoader());
  }
Exemplo n.º 14
0
 /** Serializes this object. */
 public void readFields(DataInput in) throws IOException {
   int length = WritableUtils.readVInt(in);
   byte[] bytes = new byte[length];
   in.readFully(bytes, 0, length);
   WikipediaPage.readPage(this, new String(bytes, "UTF-8"));
   language = in.readUTF();
 }
Exemplo n.º 15
0
  private void readRowByte(
      final DataInput input,
      Rectangle srcRegion,
      int xSub,
      int ySub,
      byte[] rowDataByte,
      final int off,
      final int length,
      WritableRaster destChannel,
      Raster srcChannel,
      int y)
      throws IOException {
    // If subsampled or outside source region, skip entire row
    if (y % ySub != 0 || y < srcRegion.y || y >= srcRegion.y + srcRegion.height) {
      input.skipBytes(length);

      return;
    }

    input.readFully(rowDataByte, off, length);

    // Subsample horizontal
    if (xSub != 1) {
      for (int x = 0; x < srcRegion.width / xSub; x++) {
        rowDataByte[srcRegion.x + x] = rowDataByte[srcRegion.x + x * xSub];
      }
    }

    int dstY = (y - srcRegion.y) / ySub;
    destChannel.setDataElements(0, dstY, srcChannel);
  }
  @Override
  public void readFields(DataInput in) throws IOException {
    initialize();
    int numFields = in.readInt();

    for (int i = 0; i < numFields; ++i) {
      byte type = in.readByte();

      if (type == BYTE) {
        fields.add(in.readByte());
      } else if (type == BOOLEAN) {
        fields.add(in.readBoolean());
      } else if (type == INT) {
        fields.add(in.readInt());
      } else if (type == LONG) {
        fields.add(in.readLong());
      } else if (type == FLOAT) {
        fields.add(in.readFloat());
      } else if (type == DOUBLE) {
        fields.add(in.readDouble());
      } else if (type == STRING) {
        fields.add(in.readUTF());
      } else if (type == BYTE_ARRAY) {
        int len = in.readShort();
        byte[] bytes = new byte[len];
        in.readFully(bytes);
        fields.add(bytes);
      } else {
        throw new IllegalArgumentException("Failed encoding, unknown element type in stream");
      }
    }
  }
Exemplo n.º 17
0
 @Override
 public void readFields(DataInput input) throws IOException {
   int encodedByteLengthAndBool = WritableUtils.readVInt(input);
   int byteLength = Math.abs(encodedByteLengthAndBool) - 1;
   this.byteValue = new byte[byteLength];
   input.readFully(byteValue, 0, byteLength);
   int sortOrderAndDeterminism = WritableUtils.readVInt(input);
   if (sortOrderAndDeterminism <= 2) {
     // client is on an older version
     this.determinism = encodedByteLengthAndBool > 0 ? Determinism.ALWAYS : Determinism.PER_ROW;
     this.sortOrder = SortOrder.fromSystemValue(sortOrderAndDeterminism);
     ;
   } else {
     int determinismOrdinal = (sortOrderAndDeterminism >> 2) - 1;
     this.determinism = Determinism.values()[determinismOrdinal];
     int sortOrderValue =
         sortOrderAndDeterminism & ((1 << 2) - 1); // get the least 2 significant bits
     this.sortOrder = SortOrder.fromSystemValue(sortOrderValue);
   }
   int typeOrdinal = WritableUtils.readVInt(input);
   if (typeOrdinal < 0) {
     this.type = null;
   } else {
     this.type = PDataType.values()[typeOrdinal];
   }
   if (this.byteValue.length == 0) {
     this.value = null;
   } else {
     this.value = this.type.toObject(byteValue, 0, byteValue.length, this.type, sortOrder);
   }
 }
Exemplo n.º 18
0
  /** Creates new ResourceMap */
  public ResourceMap(DataInput di) throws IOException {
    di.readFully(headerCopy);
    nextResourceMap = di.readInt();
    fileReferenceNumber = di.readUnsignedShort();
    attributes = di.readUnsignedShort();
    int typeOffset = di.readUnsignedShort();
    int nameOffset = di.readUnsignedShort();
    int typeCount = di.readUnsignedShort() + 1;

    // Read types
    types = new ResourceType[typeCount];
    for (int i = 0; i < typeCount; i++) {
      types[i] = new ResourceType(di);
    }

    // Read the references
    for (int i = 0; i < typeCount; i++) {
      types[i].readRefs(di);
    }

    // Read the names
    for (int i = 0; i < typeCount; i++) {
      types[i].readNames(di);
    }
  }
Exemplo n.º 19
0
 @Override
 void read(final DataInput in) throws IOException {
   final int s = in.readInt();
   final byte[] p = new byte[s];
   in.readFully(p);
   payload = p;
 }
 public void readInternal(DataInput in) throws IOException {
   name = in.readUTF();
   int targetBytesLength = in.readInt();
   byte[] targetBytes = new byte[targetBytesLength];
   in.readFully(targetBytes);
   this.target = (ActorRef) Util.toObject(targetBytes);
 }
Exemplo n.º 21
0
 /*
  * Read a String as a Network Int n, followed by n Bytes
  * Alternative to 16 bit read/writeUTF.
  * Encoding standard is... ?
  *
  */
 public static String readString(DataInput in) throws IOException {
   int length = in.readInt();
   if (length == -1) return null;
   byte[] buffer = new byte[length];
   in.readFully(buffer); // could/should use readFully(buffer,0,length)?
   return new String(buffer, "UTF-8");
 }
Exemplo n.º 22
0
  @Override
  public void readFields(DataInput dIn) throws IOException {
    instanceId = dIn.readUTF();

    // Hadoop Configuration has to get its act right
    int len = dIn.readInt();
    byte[] array = new byte[len];
    dIn.readFully(array);
    ByteArrayInputStream bais = new ByteArrayInputStream(array);
    conf = new XConfiguration(bais);

    def = new LiteWorkflowApp();
    def.readFields(dIn);
    status = Status.valueOf(dIn.readUTF());
    int numExPaths = dIn.readInt();
    for (int x = 0; x < numExPaths; x++) {
      String path = dIn.readUTF();
      String nodeName = dIn.readUTF();
      boolean isStarted = dIn.readBoolean();
      NodeInstance nodeInstance = new NodeInstance(nodeName);
      nodeInstance.started = isStarted;
      executionPaths.put(path, nodeInstance);
    }
    int numVars = dIn.readInt();
    for (int x = 0; x < numVars; x++) {
      String vName = dIn.readUTF();
      String vVal = readBytesAsString(dIn);
      persistentVars.put(vName, vVal);
    }
    refreshLog();
  }
Exemplo n.º 23
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) {
    }
  }
Exemplo n.º 24
0
 private byte buffered(byte[] buffer, int pos, int utfLenght, DataInput in) throws IOException {
   int innerPos = pos % buffer.length;
   if (innerPos == 0) {
     int length = Math.min(buffer.length, utfLenght - pos);
     in.readFully(buffer, 0, length);
   }
   return buffer[innerPos];
 }
Exemplo n.º 25
0
 public void readFields(DataInput in) throws IOException {
   timespent = in.readInt();
   estimated_revenue = in.readDouble();
   int len = in.readInt();
   byte[] b = new byte[len];
   in.readFully(b);
   query_term = new String(b);
 }
Exemplo n.º 26
0
 @Override
 public void readFully(byte b[], int off, int len) {
   try {
     input.readFully(b, off, len);
   } catch (IOException e) {
     throw new IllegalStateException(e);
   }
 }
Exemplo n.º 27
0
  /** Reads a fixed-size field and interprets it as a string padded with zeros. */
  public static String readStringFixedSize(final DataInput in, int size) throws IOException {
    byte[] b = new byte[size];
    in.readFully(b);
    int n = b.length;
    while (n > 0 && b[n - 1] == 0) --n;

    return toString(b, 0, n);
  }
Exemplo n.º 28
0
 private int read(byte[] a) throws IOException {
   if (in != null) {
     return in.read(a);
   } else {
     din.readFully(a);
     return a.length;
   }
 }
Exemplo n.º 29
0
  @Override
  public void read(DataInput stream, int length) throws IOException {
    index = stream.readInt();
    begin = stream.readInt();

    block = new byte[length - 9];
    stream.readFully(block);
  }
Exemplo n.º 30
0
 private int read(byte[] a, int offset, int num) throws IOException {
   if (in != null) {
     return in.read(a, offset, num);
   } else {
     din.readFully(a, offset, num);
     return num;
   }
 }