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

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

@Override
public void handleRequest(final DataInput input, final ActiveOperation.ResultHandler<Void> resultHandler, final ManagementRequestContext<ServerInventory> context) throws IOException {
    final byte param = input.readByte(); // Started / Failed PARAM_OK
    final String message = input.readUTF(); // Server started/failed message
    context.executeAsync(new ManagementRequestContext.AsyncTask<ServerInventory>() {
        @Override
        public void execute(ManagementRequestContext<ServerInventory> serverInventoryManagementRequestContext) throws Exception {
            try {
                final ServerInventory inventory = context.getAttachment();
                if(param == DomainServerProtocol.PARAM_OK) {
                    inventory.serverStarted(serverProcessName);
                } else {
                    inventory.serverStartFailed(serverProcessName);
                }
            } finally {
                resultHandler.done(null);
            }
        }
    });
}
 
源代码2 项目: gemfirexd-oss   文件: DiskInitFileParser.java
private void readEndOfRecord(DataInput di) throws IOException {
  int b = di.readByte();
  if (b != DiskInitFile.END_OF_RECORD_ID) {
    if (b == 0) {
      // this is expected if this is the last record and we died while writing it.
      throw new EOFException("found partial last record");
    } else {
      // Our implementation currently relies on all unwritten bytes having
      // a value of 0. So throw this exception if we find one we didn't expect.
      throw new IllegalStateException("expected end of record (byte=="
                                      + DiskInitFile.END_OF_RECORD_ID
                                      + ") or zero but found " + b);
    }
  }
}
 
源代码3 项目: coming   文件: jMutRepair_0045_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));
}
 
@Override
 public void readFields(DataInput in) throws IOException {
   byte version = in.readByte();
   if (version != VERSION) {
throw new IOException("Unknown version of delegation token " + 
                             version);
   }
   owner.readFields(in, Text.DEFAULT_MAX_LEN);
   renewer.readFields(in, Text.DEFAULT_MAX_LEN);
   realUser.readFields(in, Text.DEFAULT_MAX_LEN);
   issueDate = WritableUtils.readVLong(in);
   maxDate = WritableUtils.readVLong(in);
   sequenceNumber = WritableUtils.readVInt(in);
   masterKeyId = WritableUtils.readVInt(in);
 }
 
源代码5 项目: jdk8u-jdk   文件: ZoneInfoFile.java
public static ZoneInfo getZoneInfo(DataInput in, String zoneId) throws Exception {
    byte type = in.readByte();
    // TBD: assert ZRULES:
    int stdSize = in.readInt();
    long[] stdTrans = new long[stdSize];
    for (int i = 0; i < stdSize; i++) {
        stdTrans[i] = readEpochSec(in);
    }
    int [] stdOffsets = new int[stdSize + 1];
    for (int i = 0; i < stdOffsets.length; i++) {
        stdOffsets[i] = readOffset(in);
    }
    int savSize = in.readInt();
    long[] savTrans = new long[savSize];
    for (int i = 0; i < savSize; i++) {
        savTrans[i] = readEpochSec(in);
    }
    int[] savOffsets = new int[savSize + 1];
    for (int i = 0; i < savOffsets.length; i++) {
        savOffsets[i] = readOffset(in);
    }
    int ruleSize = in.readByte();
    ZoneOffsetTransitionRule[] rules = new ZoneOffsetTransitionRule[ruleSize];
    for (int i = 0; i < ruleSize; i++) {
        rules[i] = new ZoneOffsetTransitionRule(in);
    }
    return getZoneInfo(zoneId, stdTrans, stdOffsets, savTrans, savOffsets, rules);
}
 
源代码6 项目: arcusplatform   文件: ZclDataUtil.java
private static long readBits(DataInput input, int bytes) throws IOException {
   long result = 0;
   long shift = 0;
   for (int i = 0; i < bytes; ++i) {
      result = result | ((input.readByte() & 0xFFL) << shift);
      shift += 8;
   }

   return result;
}
 
源代码7 项目: spork   文件: SedesHelper.java
/**
 * @param in to read bytes from
 * @return decode value
 * @throws IOException if {@link DataInput} throws {@link IOException}
 * @throws IllegalArgumentException if variable-length value does not terminate
 *  after 9 bytes have been read
 * @see #writeUnsignedVarLong(long, DataOutput)
 */
public static long readUnsignedVarLong(DataInput in) throws IOException {
    long value = 0L;
    int i = 0;
    long b;
    while (((b = in.readByte()) & 0x80L) != 0) {
        value |= (b & 0x7F) << i;
        i += 7;
        if (i > 63) {
            throw new RuntimeException("Variable length quantity is too long");
        }
    }
    return value | (b << i);
}
 
源代码8 项目: gemfirexd-oss   文件: SerializedObjectPartList.java
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
  boolean keysPresent = in.readBoolean();
  if (keysPresent) {
    this.keys = new ArrayList();
  }
  this.hasKeys = keysPresent;
  int numObjects = in.readInt();
  this.objectTypeArray = new byte[numObjects];
  if (numObjects > 0) {
    for (int index = 0; index < numObjects; ++index) {
      if (keysPresent) {
        Object key = DataSerializer.readObject(in);
        this.keys.add(key);
      }
      byte objectType = in.readByte();
      this.objectTypeArray[index] = objectType;
      Object value;
      if (objectType==EXCEPTION) {
        byte[] exBytes = DataSerializer.readByteArray(in);
        value = CacheServerHelper.deserialize(exBytes);
        // ignore the exception string meant for native clients
        DataSerializer.readString(in);
      }
      else {
        value = DataSerializer.readByteArray(in);
      }
      this.objects.add(value);
    }
  }
}
 
源代码9 项目: gemfirexd-oss   文件: IndexCreationMsg.java
@Override
public void fromData(DataInput in)
    throws IOException, ClassNotFoundException {
  super.fromData(in);
  this.name = in.readUTF();
  this.fromClause = in.readUTF();
  this.indexedExpression = in.readUTF();
  this.indexType = in.readByte();
  this.importsNeeded = in.readBoolean();
  if (this.importsNeeded)
    this.imports = in.readUTF();
  // this.ifNew = in.readBoolean();
  // this.ifOld = in.readBoolean();
}
 
源代码10 项目: incubator-hivemall   文件: ZigZagLEB128Codec.java
public static int readUnsignedInt(@Nonnull final DataInput in) throws IOException {
    int value = 0;
    int i = 0;
    int b;
    while (((b = in.readByte()) & 0x80) != 0) {
        value |= (b & 0x7F) << i;
        i += 7;
        if (i > 35) {
            throw new IllegalArgumentException("Variable length quantity is too long: " + i);
        }
    }
    return value | (b << i);
}
 
源代码11 项目: FastBootWeixin   文件: CompressLZF.java
public void expand(DataInput in, byte[] out, int outPos, int outLen) throws IOException {
    // if ((inPos | outPos | outLen) < 0) {
    assert(outLen>=0);
    do {
        int ctrl = in.readByte() & 255;
        if (ctrl < MAX_LITERAL) {
            // literal run of length = ctrl + 1,
            ctrl++;
            // copy to output and move forward this many bytes
            in.readFully(out,outPos,ctrl);
            outPos += ctrl;
        } else {
            // back reference
            // the highest 3 bits are the match length
            int len = ctrl >> 5;
            // if the length is maxed, add the next byte to the length
            if (len == 7) {
                len += in.readByte() & 255;
            }
            // minimum back-reference is 3 bytes,
            // so 2 was subtracted before storing size
            len += 2;

            // ctrl is now the offset for a back-reference...
            // the logical AND operation removes the length bits
            ctrl = -((ctrl & 0x1f) << 8) - 1;

            // the next byte augments/increases the offset
            ctrl -= in.readByte() & 255;

            // copy the back-reference bytes from the given
            // location in output to current position
            ctrl += outPos;
            if (outPos + len >= out.length) {
                // reduce array bounds checking
                throw new ArrayIndexOutOfBoundsException();
            }
            for (int i = 0; i < len; i++) {
                out[outPos++] = out[ctrl++];
            }
        }
    } while (outPos < outLen);
}
 
源代码12 项目: threetenbp   文件: LocalDate.java
static LocalDate readExternal(DataInput in) throws IOException {
    int year = in.readInt();
    int month = in.readByte();
    int dayOfMonth = in.readByte();
    return LocalDate.of(year, month, dayOfMonth);
}
 
源代码13 项目: Java8CN   文件: ThaiBuddhistDate.java
static ThaiBuddhistDate readExternal(DataInput in) throws IOException {
    int year = in.readInt();
    int month = in.readByte();
    int dayOfMonth = in.readByte();
    return ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth);
}
 
源代码14 项目: threetenbp   文件: Ser.java
static Object read(DataInput in) throws IOException {
    byte type = in.readByte();
    return readInternal(type, in);
}
 
源代码15 项目: jdk8u-jdk   文件: Ser.java
static Object read(DataInput in) throws IOException, ClassNotFoundException {
    byte type = in.readByte();
    return readInternal(type, in);
}
 
源代码16 项目: gemfirexd-oss   文件: DistributedPutAllOperation.java
/**
 * Constructor to use when receiving a putall from someone else
 */
public PutAllEntryData(DataInput in, EventID baseEventID, int idx,
    Version version, ByteArrayDataInput bytesIn) throws IOException,
    ClassNotFoundException {
  this.key = DataSerializer.readObject(in);
  byte flgs = in.readByte();
  if ((flgs & IS_OBJECT) != 0) {
    this.value = DataSerializer.readObject(in);
  }
  else {
    byte[] bb = DataSerializer.readByteArray(in);
    if ((flgs & IS_CACHED_DESER) != 0) {
      if (CachedDeserializableFactory.preferObject()) {
        this.value = EntryEventImpl.deserialize(bb, version, bytesIn);
      }
      else {
        this.value = CachedDeserializableFactory.create(bb);
      }
    }
    else {
      this.value = bb;
    }
  }
  this.oldValue = null;
  this.op = Operation.fromOrdinal(in.readByte());
  this.flags = in.readByte();
  if ((this.flags & FILTER_ROUTING) != 0) {
    this.filterRouting = (FilterRoutingInfo)DataSerializer.readObject(in);
  }
  if ((this.flags & VERSION_TAG) != 0) {
    boolean persistentTag = (this.flags & PERSISTENT_TAG) != 0;
    this.versionTag = VersionTag.create(persistentTag, in);
  }
  if (isUsedFakeEventId()) {
    this.eventID = new EventID();
    InternalDataSerializer.invokeFromData(this.eventID, in);
  }
  else {
    this.eventID = new EventID(baseEventID, idx);
  }
  if ((this.flags & HAS_CALLBACKARG) != 0) {
    this.callbackArg = DataSerializer.readObject(in);
  }
  else {
    this.callbackArg = null;
  }
  if ((this.flags & HAS_TAILKEY) != 0) {
    this.tailKey = InternalDataSerializer.readSignedVL(in);
  }
}
 
源代码17 项目: commons-bcel   文件: Constant.java
/**
 * Reads one constant from the given input, the type depends on a tag byte.
 *
 * @param dataInput Input stream
 * @return Constant object
 * @throws IOException if an I/O error occurs reading from the given {@code dataInput}.
 * @throws ClassFormatException if the next byte is not recognized
 * @since 6.0 made public
 */
public static Constant readConstant(final DataInput dataInput) throws IOException, ClassFormatException {
    final byte b = dataInput.readByte(); // Read tag byte
    switch (b) {
    case Const.CONSTANT_Class:
        return new ConstantClass(dataInput);
    case Const.CONSTANT_Fieldref:
        return new ConstantFieldref(dataInput);
    case Const.CONSTANT_Methodref:
        return new ConstantMethodref(dataInput);
    case Const.CONSTANT_InterfaceMethodref:
        return new ConstantInterfaceMethodref(dataInput);
    case Const.CONSTANT_String:
        return new ConstantString(dataInput);
    case Const.CONSTANT_Integer:
        return new ConstantInteger(dataInput);
    case Const.CONSTANT_Float:
        return new ConstantFloat(dataInput);
    case Const.CONSTANT_Long:
        return new ConstantLong(dataInput);
    case Const.CONSTANT_Double:
        return new ConstantDouble(dataInput);
    case Const.CONSTANT_NameAndType:
        return new ConstantNameAndType(dataInput);
    case Const.CONSTANT_Utf8:
        return ConstantUtf8.getInstance(dataInput);
    case Const.CONSTANT_MethodHandle:
        return new ConstantMethodHandle(dataInput);
    case Const.CONSTANT_MethodType:
        return new ConstantMethodType(dataInput);
    case Const.CONSTANT_Dynamic:
        return new ConstantDynamic(dataInput);
    case Const.CONSTANT_InvokeDynamic:
        return new ConstantInvokeDynamic(dataInput);
    case Const.CONSTANT_Module:
        return new ConstantModule(dataInput);
    case Const.CONSTANT_Package:
        return new ConstantPackage(dataInput);
    default:
        throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
    }
}
 
源代码18 项目: dragonwell8_jdk   文件: MonthDay.java
static MonthDay readExternal(DataInput in) throws IOException {
    byte month = in.readByte();
    byte day = in.readByte();
    return MonthDay.of(month, day);
}
 
源代码19 项目: gemfirexd-oss   文件: RemotePutMessage.java
@Override
public void fromData(DataInput in)
    throws IOException, ClassNotFoundException {
  super.fromData(in);
  final Version version = InternalDataSerializer.getVersionForDataStream(in);
  final boolean isVer11 = (Version.SQLF_11.compareTo(version) <= 0);

  setKey(DataSerializer.readObject(in));
  final int extraFlags = in.readUnsignedByte();
  this.deserializationPolicy = (byte)(extraFlags
      & DistributedCacheOperation.DESERIALIZATION_POLICY_MASK);
  if (!isVer11) {
    this.cbArg = DataSerializer.readObject(in);
  }
  this.lastModified = in.readLong();
  this.op = Operation.fromOrdinal(in.readByte());
  if (isVer11 && (extraFlags & HAS_CALLBACKARG) != 0) {
    this.cbArg = DataSerializer.readObject(in);
  }
  if ((extraFlags & HAS_BRIDGE_CONTEXT) != 0) {
    this.bridgeContext = DataSerializer.readObject(in);
  }
  if ((extraFlags & HAS_ORIGINAL_SENDER) != 0) {
    this.originalSender = DataSerializer.readObject(in);
  }
  this.eventId = new EventID();
  InternalDataSerializer.invokeFromData(this.eventId, in);

  final short flags = this.flags;
  this.ifNew = (flags & IF_NEW) != 0;
  this.ifOld = (flags & IF_OLD) != 0;
  this.requireOldValue = (flags & REQUIRED_OLD_VAL) != 0;
  this.hasOldValue = (flags & HAS_OLD_VAL) != 0;
  this.cacheWrite = (flags & CACHE_WRITE) != 0;
  this.useOriginRemote = (flags & USE_ORIGIN_REMOTE) != 0;
  this.isPutDML = (flags & IS_PUT_DML) != 0;

  if ((flags & HAS_EXPECTED_OLD_VAL) != 0) {
    this.expectedOldValue = DataSerializer.readObject(in);
  }

  if (this.hasOldValue) {
    this.oldValueIsSerialized = in.readByte();
    if (this.oldValueIsSerialized == VALUE_IS_OBJECT) {
      setOldValObj(DataSerializer.readObject(in));
    }
    else {
      setOldValBytes(DataSerializer.readByteArray(in));
    }
  }
  if (this.deserializationPolicy ==
      DistributedCacheOperation.DESERIALIZATION_POLICY_EAGER) {
    setValObj(DataSerializer.readObject(in));
  }
  else {
    setValBytes(DataSerializer.readByteArray(in));
  }
  if ((flags & HAS_DELTA_BYTES) != 0) {
    this.applyDeltaBytes = true;
    this.deltaBytes = DataSerializer.readByteArray(in);
  }
  if ((extraFlags & HAS_VERSION_TAG) != 0) {
    this.versionTag = DataSerializer.readObject(in);
  }
}
 
源代码20 项目: jdk8u_jdk   文件: Ser.java
/**
 * Reads the state from the stream.
 *
 * @param in  the input stream, not null
 * @return the created object, not null
 * @throws IOException if an error occurs
 */
static ZoneOffset readOffset(DataInput in) throws IOException {
    int offsetByte = in.readByte();
    return (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(offsetByte * 900));
}