下面列出了怎么用java.io.StreamCorruptedException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Returns an output stream (may put out header information
* relating to the success of the call).
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @exception StreamCorruptedException If result stream previously
* acquired
* @exception IOException For any other problem with I/O.
*/
public ObjectOutput getResultStream(boolean success) throws IOException {
/* make sure result code only marshaled once. */
if (resultStarted)
throw new StreamCorruptedException("result already in progress");
else
resultStarted = true;
// write out return header
// return header, part 1 (read by Transport)
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeByte(TransportConstants.Return);// transport op
getOutputStream(true); // creates a MarshalOutputStream
// return header, part 2 (read by client-side RemoteCall)
if (success) //
out.writeByte(TransportConstants.NormalReturn);
else
out.writeByte(TransportConstants.ExceptionalReturn);
out.writeID(); // write id for gcAck
return out;
}
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
switch (type) {
case DURATION_TYPE: return Duration.readExternal(in);
case INSTANT_TYPE: return Instant.readExternal(in);
case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
case YEAR_TYPE: return Year.readExternal(in);
case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
case PERIOD_TYPE: return Period.readExternal(in);
default:
throw new StreamCorruptedException("Unknown serialized type");
}
}
/**
* Returns an output stream (may put out header information
* relating to the success of the call).
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @exception StreamCorruptedException If result stream previously
* acquired
* @exception IOException For any other problem with I/O.
*/
public ObjectOutput getResultStream(boolean success) throws IOException {
/* make sure result code only marshaled once. */
if (resultStarted)
throw new StreamCorruptedException("result already in progress");
else
resultStarted = true;
// write out return header
// return header, part 1 (read by Transport)
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeByte(TransportConstants.Return);// transport op
getOutputStream(true); // creates a MarshalOutputStream
// return header, part 2 (read by client-side RemoteCall)
if (success) //
out.writeByte(TransportConstants.NormalReturn);
else
out.writeByte(TransportConstants.ExceptionalReturn);
out.writeID(); // write id for gcAck
return out;
}
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException,ClassNotFoundException
{
int type = read();
if( type < 0 )
throw new EOFException();
switch( type )
{
case 0:
return super.readClassDescriptor();
case 1:
Class<?> clazz = loadClass(readUTF());
return ObjectStreamClass.lookup(clazz);
default:
throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
}
}
/**
* Returns an output stream (may put out header information
* relating to the success of the call).
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @exception StreamCorruptedException If result stream previously
* acquired
* @exception IOException For any other problem with I/O.
*/
public ObjectOutput getResultStream(boolean success) throws IOException {
/* make sure result code only marshaled once. */
if (resultStarted)
throw new StreamCorruptedException("result already in progress");
else
resultStarted = true;
// write out return header
// return header, part 1 (read by Transport)
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeByte(TransportConstants.Return);// transport op
getOutputStream(true); // creates a MarshalOutputStream
// return header, part 2 (read by client-side RemoteCall)
if (success) //
out.writeByte(TransportConstants.NormalReturn);
else
out.writeByte(TransportConstants.ExceptionalReturn);
out.writeID(); // write id for gcAck
return out;
}
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
switch (type) {
case DURATION_TYPE: return Duration.readExternal(in);
case INSTANT_TYPE: return Instant.readExternal(in);
case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
case YEAR_TYPE: return Year.readExternal(in);
case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
case PERIOD_TYPE: return Period.readExternal(in);
default:
throw new StreamCorruptedException("Unknown serialized type");
}
}
public void readData(InputStreamHook stream) throws IOException {
org.omg.CORBA.ORB orb = stream.getOrbStream().orb();
if ((orb == null) ||
!(orb instanceof com.sun.corba.se.spi.orb.ORB)) {
throw new StreamCorruptedException(
"Default data must be read first");
}
ORBVersion clientOrbVersion =
((com.sun.corba.se.spi.orb.ORB)orb).getORBVersion();
// Fix Date interop bug. For older versions of the ORB don't do
// anything for readData(). Before this used to throw
// StreamCorruptedException for older versions of the ORB where
// calledDefaultWriteObject always returns true.
if ((ORBVersionFactory.getPEORB().compareTo(clientOrbVersion) <= 0) ||
(clientOrbVersion.equals(ORBVersionFactory.getFOREIGN()))) {
// XXX I18N and logging needed.
throw new StreamCorruptedException("Default data must be read first");
}
}
public void readData(InputStreamHook stream) throws IOException {
org.omg.CORBA.ORB orb = stream.getOrbStream().orb();
if ((orb == null) ||
!(orb instanceof com.sun.corba.se.spi.orb.ORB)) {
throw new StreamCorruptedException(
"Default data must be read first");
}
ORBVersion clientOrbVersion =
((com.sun.corba.se.spi.orb.ORB)orb).getORBVersion();
// Fix Date interop bug. For older versions of the ORB don't do
// anything for readData(). Before this used to throw
// StreamCorruptedException for older versions of the ORB where
// calledDefaultWriteObject always returns true.
if ((ORBVersionFactory.getPEORB().compareTo(clientOrbVersion) <= 0) ||
(clientOrbVersion.equals(ORBVersionFactory.getFOREIGN()))) {
// XXX I18N and logging needed.
throw new StreamCorruptedException("Default data must be read first");
}
}
@SuppressWarnings("null")
private Class<?> getType(String s) throws StreamCorruptedException {
int dim = 0;
while (s.endsWith("[]")) {
s = "" + s.substring(0, s.length() - 2);
dim++;
}
Class<?> c;
final Tag t = Tag.byName(s);
if (t != null)
c = t.c;
else
c = yggdrasil.getClass(s);
if (c == null)
throw new StreamCorruptedException("Invalid type " + s);
if (dim == 0)
return c;
while (dim-- > 0)
c = Array.newInstance(c, 0).getClass();
return c;
}
/**
* Returns an output stream (may put out header information
* relating to the success of the call).
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @exception StreamCorruptedException If result stream previously
* acquired
* @exception IOException For any other problem with I/O.
*/
public ObjectOutput getResultStream(boolean success) throws IOException {
/* make sure result code only marshaled once. */
if (resultStarted)
throw new StreamCorruptedException("result already in progress");
else
resultStarted = true;
// write out return header
// return header, part 1 (read by Transport)
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeByte(TransportConstants.Return);// transport op
getOutputStream(true); // creates a MarshalOutputStream
// return header, part 2 (read by client-side RemoteCall)
if (success) //
out.writeByte(TransportConstants.NormalReturn);
else
out.writeByte(TransportConstants.ExceptionalReturn);
out.writeID(); // write id for gcAck
return out;
}
private long approximateLastIndex(int cycle, SingleChronicleQueue queue,
StoreTailer tailer) {
try (SingleChronicleQueueStore wireStore = queue.storeForCycle(cycle, queue.epoch(), false, null)) {
if (wireStore == null) {
return noIndex;
}
long baseIndex = rollCycle.toIndex(cycle, 0);
tailer.moveToIndex(baseIndex);
long seq = wireStore.sequenceForPosition(tailer, Long.MAX_VALUE, false);
long sequenceNumber = seq + 1;
long index = rollCycle.toIndex(cycle, sequenceNumber);
int cycleOfIndex = rollCycle.toCycle(index);
if (cycleOfIndex != cycle) {
throw new IllegalStateException(
"Expected cycle " + cycle + " but got " + cycleOfIndex);
}
return index;
} catch (StreamCorruptedException | UnrecoverableTimeoutException e) {
throw new IllegalStateException(e);
}
}
/**
* Returns an output stream (may put out header information
* relating to the success of the call).
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @exception StreamCorruptedException If result stream previously
* acquired
* @exception IOException For any other problem with I/O.
*/
public ObjectOutput getResultStream(boolean success) throws IOException {
/* make sure result code only marshaled once. */
if (resultStarted)
throw new StreamCorruptedException("result already in progress");
else
resultStarted = true;
// write out return header
// return header, part 1 (read by Transport)
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeByte(TransportConstants.Return);// transport op
getOutputStream(true); // creates a MarshalOutputStream
// return header, part 2 (read by client-side RemoteCall)
if (success) //
out.writeByte(TransportConstants.NormalReturn);
else
out.writeByte(TransportConstants.ExceptionalReturn);
out.writeID(); // write id for gcAck
return out;
}
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
switch (type) {
case DURATION_TYPE: return Duration.readExternal(in);
case INSTANT_TYPE: return Instant.readExternal(in);
case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
case YEAR_TYPE: return Year.readExternal(in);
case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
case PERIOD_TYPE: return Period.readExternal(in);
default:
throw new StreamCorruptedException("Unknown serialized type");
}
}
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
switch (type) {
case DURATION_TYPE: return Duration.readExternal(in);
case INSTANT_TYPE: return Instant.readExternal(in);
case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
case YEAR_TYPE: return Year.readExternal(in);
case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
case PERIOD_TYPE: return Period.readExternal(in);
default:
throw new StreamCorruptedException("Unknown serialized type");
}
}
/**
* Returns an output stream (may put out header information
* relating to the success of the call).
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @exception StreamCorruptedException If result stream previously
* acquired
* @exception IOException For any other problem with I/O.
*/
public ObjectOutput getResultStream(boolean success) throws IOException {
/* make sure result code only marshaled once. */
if (resultStarted)
throw new StreamCorruptedException("result already in progress");
else
resultStarted = true;
// write out return header
// return header, part 1 (read by Transport)
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeByte(TransportConstants.Return);// transport op
getOutputStream(true); // creates a MarshalOutputStream
// return header, part 2 (read by client-side RemoteCall)
if (success) //
out.writeByte(TransportConstants.NormalReturn);
else
out.writeByte(TransportConstants.ExceptionalReturn);
out.writeID(); // write id for gcAck
return out;
}
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException {
switch (type) {
case ZRULES:
return ZoneRules.readExternal(in);
case ZOT:
return ZoneOffsetTransition.readExternal(in);
case ZOTRULE:
return ZoneOffsetTransitionRule.readExternal(in);
default:
throw new StreamCorruptedException("Unknown serialized type");
}
}
/**
* Deserializes an {@link MBeanInfo} from an {@link ObjectInputStream}.
* @serialData
* For compatibility reasons, an object of this class is deserialized as follows.
* <p>
* The method {@link ObjectInputStream#defaultReadObject defaultReadObject()}
* is called first to deserialize the object except the field
* {@code descriptor}, which is not serialized in the default way. Then the method
* {@link ObjectInputStream#read read()} is called to read a byte, the field
* {@code descriptor} is deserialized according to the value of the byte value:
* <ul>
* <li>1. The method {@link ObjectInputStream#readObject readObject()}
* is called twice to obtain the field names (a {@code String[]}) and
* the field values (a {@code Object[]}) of the {@code descriptor}.
* The two obtained values then are used to construct
* an {@link ImmutableDescriptor} instance for the field
* {@code descriptor};</li>
* <li>0. The value for the field {@code descriptor} is obtained directly
* by calling the method {@link ObjectInputStream#readObject readObject()}.
* If the obtained value is null, the field {@code descriptor} is set to
* {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li>
* <li>-1. This means that there is no byte to read and that the object is from
* an earlier version of the JMX API. The field {@code descriptor} is set to
* {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}.</li>
* <li>Any other value. A {@link StreamCorruptedException} is thrown.</li>
* </ul>
*
* @since 1.6
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
switch (in.read()) {
case 1:
final String[] names = (String[])in.readObject();
final Object[] values = (Object[]) in.readObject();
descriptor = (names.length == 0) ?
ImmutableDescriptor.EMPTY_DESCRIPTOR :
new ImmutableDescriptor(names, values);
break;
case 0:
descriptor = (Descriptor)in.readObject();
if (descriptor == null) {
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
break;
case -1: // from an earlier version of the JMX API
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
break;
default:
throw new StreamCorruptedException("Got unexpected byte.");
}
}
private ZoneRules loadData(InputStream in) throws Exception {
DataInputStream dis = new DataInputStream(in);
if (dis.readByte() != 1) {
throw new StreamCorruptedException("File format not recognised");
}
String groupId = dis.readUTF();
if (!"TZDB-ZONE".equals(groupId)) {
throw new StreamCorruptedException("File format not recognised");
}
return ZoneRulesCompat.readZoneRules(dis);
}
void readFields(java.util.Map fieldToValueMap)
throws InvalidClassException, StreamCorruptedException,
ClassNotFoundException, IOException {
if (mustUseRemoteValueMembers()) {
inputRemoteMembersForReadFields(fieldToValueMap);
} else
inputCurrentClassFieldsForReadFields(fieldToValueMap);
}
/**
* Loader must be non-null;
*/
public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
throws IOException, StreamCorruptedException {
super(in);
if (loader == null) {
throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
}
this.loader = loader;
}
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException {
switch (type) {
case ZRULES:
return ZoneRules.readExternal(in);
case ZOT:
return ZoneOffsetTransition.readExternal(in);
case ZOTRULE:
return ZoneOffsetTransitionRule.readExternal(in);
default:
throw new StreamCorruptedException("Unknown serialized type");
}
}
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
out.writeByte(_type);
switch (_type) {
case PROGRAM_CHROMOSOME: ((ProgramChromosome)_object).write(out); break;
default:
throw new StreamCorruptedException("Unknown serialized type.");
}
}
public void excessiveField(final Object o, final FieldContext field) throws StreamCorruptedException {
for (final FieldHandler h : fieldHandlers) {
if (h.excessiveField(o, field))
return;
}
throw new StreamCorruptedException("Excessive field " + field.id + " in class " + o.getClass().getCanonicalName() + " was not handled");
}
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
switch (type) {
case CHRONO_TYPE: return AbstractChronology.readExternal(in);
case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in);
case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in);
case JAPANESE_DATE_TYPE: return JapaneseDate.readExternal(in);
case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in);
case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in);
case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in);
case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in);
case CHRONO_PERIOD_TYPE: return ChronoPeriodImpl.readExternal(in);
default: throw new StreamCorruptedException("Unknown serialized type");
}
}
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException {
switch (type) {
case ZRULES:
return ZoneRules.readExternal(in);
case ZOT:
return ZoneOffsetTransition.readExternal(in);
case ZOTRULE:
return ZoneOffsetTransitionRule.readExternal(in);
default:
throw new StreamCorruptedException("Unknown serialized type");
}
}
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
int type = read();
if (type < 0)
throw new EOFException();
switch (type) {
case 0:
return super.readClassDescriptor();
case 1:
Class<?> clazz = loadClass(readUTF());
return ObjectStreamClass.lookup(clazz);
default:
throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
}
}
@Override
public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException {
final String r = fields.getAndRemoveObject("region", String.class);
fields.setFields(this);
RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
final ProtectedRegion region = regionManager.getRegion(r);
if (region == null)
throw new StreamCorruptedException("Invalid region " + r + " in world " + world);
this.region = region;
}
/**
* Loader must be non-null;
*/
public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
throws IOException, StreamCorruptedException {
super(in);
if (loader == null) {
throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
}
this.loader = loader;
}
/**
* Deserializes an {@link MBeanFeatureInfo} from an {@link ObjectInputStream}.
* @serialData
* For compatibility reasons, an object of this class is deserialized as follows.
* <p>
* The method {@link ObjectInputStream#defaultReadObject defaultReadObject()}
* is called first to deserialize the object except the field
* {@code descriptor}, which is not serialized in the default way. Then the method
* {@link ObjectInputStream#read read()} is called to read a byte, the field
* {@code descriptor} is deserialized according to the value of the byte value:
* <ul>
* <li>1. The method {@link ObjectInputStream#readObject readObject()}
* is called twice to obtain the field names (a {@code String[]}) and
* the field values (a {@code Object[]}) of the {@code descriptor}.
* The two obtained values then are used to construct
* an {@link ImmutableDescriptor} instance for the field
* {@code descriptor};</li>
* <li>0. The value for the field {@code descriptor} is obtained directly
* by calling the method {@link ObjectInputStream#readObject readObject()}.
* If the obtained value is null, the field {@code descriptor} is set to
* {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li>
* <li>-1. This means that there is no byte to read and that the object is from
* an earlier version of the JMX API. The field {@code descriptor} is set
* to {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}</li>
* <li>Any other value. A {@link StreamCorruptedException} is thrown.</li>
* </ul>
*
* @since 1.6
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
switch (in.read()) {
case 1:
final String[] names = (String[])in.readObject();
final Object[] values = (Object[]) in.readObject();
descriptor = (names.length == 0) ?
ImmutableDescriptor.EMPTY_DESCRIPTOR :
new ImmutableDescriptor(names, values);
break;
case 0:
descriptor = (Descriptor)in.readObject();
if (descriptor == null) {
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
break;
case -1: // from an earlier version of the JMX API
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
break;
default:
throw new StreamCorruptedException("Got unexpected byte.");
}
}
/**
* Loader must be non-null;
*/
public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
throws IOException, StreamCorruptedException {
super(in);
if (loader == null) {
throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
}
this.loader = loader;
}