当前位置: 首页>>代码示例>>Java>>正文


Java OptionalDataException类代码示例

本文整理汇总了Java中java.io.OptionalDataException的典型用法代码示例。如果您正苦于以下问题:Java OptionalDataException类的具体用法?Java OptionalDataException怎么用?Java OptionalDataException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OptionalDataException类属于java.io包,在下文中一共展示了OptionalDataException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createOptionalDataException

import java.io.OptionalDataException; //导入依赖的package包/类
private OptionalDataException createOptionalDataException() {
    try {
        OptionalDataException result
            = (OptionalDataException)
               OPT_DATA_EXCEPTION_CTOR.newInstance(new Object[] {
                   Boolean.TRUE });

        if (result == null)
            // XXX I18N, logging needed.
            throw new Error("Created null OptionalDataException");

        return result;

    } catch (Exception ex) {
        // XXX I18N, logging needed.
        throw new Error("Couldn't create OptionalDataException", ex);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:IIOPInputStream.java

示例2: canHandle

import java.io.OptionalDataException; //导入依赖的package包/类
@Override
protected boolean canHandle(String className, String message, @Nullable Throwable throwable) {
    Throwable cause = throwable != null ? throwable.getCause() : null;
    if (cause == null) {
        return false;
    }

    if (cause instanceof ClassCastException && checkClassCastExceptionStack(cause.getStackTrace())) {
        return true;
    }

    if (cause instanceof OptionalDataException && checkOptionalDataExceptionStack(cause.getStackTrace())) {
        return true;
    }
    return false;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:EntitySerializationExceptionHandler.java

示例3: run

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Accept incoming events and processes them.
 */
@Override
public void run() {
    while (isActive) {
        try {
            final byte[] buf = new byte[maxBufferSize];
            final DatagramPacket packet = new DatagramPacket(buf, buf.length);
            server.receive(packet);
            final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(packet.getData(), packet.getOffset(), packet.getLength()));
            final LogEvent event = (LogEvent) ois.readObject();
            if (event != null) {
                log(event);
            }
        } catch (final OptionalDataException opt) {
            logger.error("OptionalDataException eof=" + opt.eof + " length=" + opt.length, opt);
        } catch (final ClassNotFoundException cnfe) {
            logger.error("Unable to locate LogEvent class", cnfe);
        } catch (final EOFException eofe) {
            logger.info("EOF encountered");
        } catch (final IOException ioe) {
            logger.error("Exception encountered on accept. Ignoring. Stack Trace :", ioe);
        }
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:27,代码来源:UDPSocketServer.java

示例4: getOptDataExceptionCtor

import java.io.OptionalDataException; //导入依赖的package包/类
private static Constructor getOptDataExceptionCtor() {

        try {

            Constructor result =

                (Constructor) AccessController.doPrivileged(
                                    new PrivilegedExceptionAction() {
                    public java.lang.Object run()
                        throws NoSuchMethodException,
                        SecurityException {

                        Constructor boolCtor
                            = OptionalDataException.class.getDeclaredConstructor(
                                                               new Class[] {
                                Boolean.TYPE });

                        boolCtor.setAccessible(true);

                        return boolCtor;
                    }});

            if (result == null)
                // XXX I18N, logging needed.
                throw new Error("Unable to find OptionalDataException constructor");

            return result;

        } catch (Exception ex) {
            // XXX I18N, logging needed.
            throw new ExceptionInInitializerError(ex);
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:IIOPInputStream.java

示例5: readExternal

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Restores this <code>DataFlavor</code> from a Serialized state.
 */

public synchronized void readExternal(ObjectInput is) throws IOException , ClassNotFoundException {
    String rcn = null;
     mimeType = (MimeType)is.readObject();

     if (mimeType != null) {
         humanPresentableName =
             mimeType.getParameter("humanPresentableName");
         mimeType.removeParameter("humanPresentableName");
         rcn = mimeType.getParameter("class");
         if (rcn == null) {
             throw new IOException("no class parameter specified in: " +
                                   mimeType);
         }
     }

     try {
         representationClass = (Class)is.readObject();
     } catch (OptionalDataException ode) {
         if (!ode.eof || ode.length != 0) {
             throw ode;
         }
         // Ensure backward compatibility.
         // Old versions didn't write the representation class to the stream.
         if (rcn != null) {
             representationClass =
                 DataFlavor.tryToLoadClass(rcn, getClass().getClassLoader());
         }
     }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:DataFlavor.java

示例6: newOptionalDataExceptionForSerialization

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Returns a new OptionalDataException with {@code eof} set to {@code true}
 * or {@code false}.
 * @param bool the value of {@code eof} in the created OptionalDataException
 * @return  a new OptionalDataException
 */
public final OptionalDataException newOptionalDataExceptionForSerialization(boolean bool) {
    try {
        Constructor<OptionalDataException> boolCtor =
                OptionalDataException.class.getDeclaredConstructor(Boolean.TYPE);
        boolCtor.setAccessible(true);
        return boolCtor.newInstance(bool);
    } catch (NoSuchMethodException | InstantiationException|
            IllegalAccessException|InvocationTargetException ex) {
        throw new InternalError("unable to create OptionalDataException", ex);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:ReflectionFactory.java

示例7: newOptionalDataException

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Test the constructor of OptionalDataExceptions.
 */
@Test
static void newOptionalDataException() {
    OptionalDataException ode = factory.newOptionalDataExceptionForSerialization(true);
    Assert.assertTrue(ode.eof, "eof wrong");
    ode = factory.newOptionalDataExceptionForSerialization(false);
    Assert.assertFalse(ode.eof, "eof wrong");

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:ReflectionFactoryTest.java

示例8: newOptionalDataExceptionForSerialization

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Return the accessible constructor for OptionalDataException signaling eof.
 * @returns the eof constructor for OptionalDataException
 */
public final Constructor<OptionalDataException> newOptionalDataExceptionForSerialization() {
    try {
        Constructor<OptionalDataException> boolCtor =
                OptionalDataException.class.getDeclaredConstructor(Boolean.TYPE);
        boolCtor.setAccessible(true);
        return boolCtor;
    } catch (NoSuchMethodException ex) {
        throw new InternalError("Constructor not found", ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ReflectionFactory.java

示例9: newOptionalDataExceptionForSerialization

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Returns a new OptionalDataException with {@code eof} set to {@code true}
 * or {@code false}.
 * @param bool the value of {@code eof} in the created OptionalDataException
 * @return  a new OptionalDataException
 */
public final OptionalDataException newOptionalDataExceptionForSerialization(boolean bool) {
    Constructor<OptionalDataException> cons = delegate.newOptionalDataExceptionForSerialization();
    try {
        return cons.newInstance(bool);
    } catch (InstantiationException|IllegalAccessException|InvocationTargetException ex) {
        throw new InternalError("unable to create OptionalDataException", ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ReflectionFactory.java

示例10: readExternal

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Restores this {@code DataFlavor} from a Serialized state.
 */
public synchronized void readExternal(ObjectInput is) throws IOException , ClassNotFoundException {
    String rcn = null;
    mimeType = (MimeType)is.readObject();

    if (mimeType != null) {
        humanPresentableName =
            mimeType.getParameter("humanPresentableName");
        mimeType.removeParameter("humanPresentableName");
        rcn = mimeType.getParameter("class");
        if (rcn == null) {
            throw new IOException("no class parameter specified in: " +
                                  mimeType);
        }
    }

    try {
        representationClass = (Class)is.readObject();
    } catch (OptionalDataException ode) {
        if (!ode.eof || ode.length != 0) {
            throw ode;
        }
        // Ensure backward compatibility.
        // Old versions didn't write the representation class to the stream.
        if (rcn != null) {
            representationClass =
                DataFlavor.tryToLoadClass(rcn, getClass().getClassLoader());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:DataFlavor.java

示例11: putObject

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Stores the given object in the Rangzen generic store, using Java's object
 * serialization and base64 coding.
 *
 * @param key The key under which to store the data.
 * @param value The object to store, which must be serializable.
 */
public void putObject(String key, Object value) throws IOException,
       StreamCorruptedException, OptionalDataException {
  ByteArrayOutputStream b = new ByteArrayOutputStream();
  ObjectOutputStream o = new ObjectOutputStream(b);
  o.writeObject(value);
  o.close();

  put(key, new String(Base64.encode(b.toByteArray(), Base64.DEFAULT))); 
}
 
开发者ID:casific,项目名称:murmur,代码行数:17,代码来源:StorageBase.java

示例12: getObject

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Retrieves the object associated with the given key.
 *
 * @param key The key under which to retrieve a object from the store.
 * @return The object requested or null if not found.
 */
public Object getObject(String key) throws IOException,
       ClassNotFoundException, StreamCorruptedException, OptionalDataException {
  String v = get(key);
  if (v == null) return null;

  ObjectInputStream o = new ObjectInputStream(
      new ByteArrayInputStream(Base64.decode(v, Base64.DEFAULT)));
  return o.readObject();
}
 
开发者ID:casific,项目名称:murmur,代码行数:16,代码来源:StorageBase.java

示例13: getAllLocations

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Get a list of all locations stored on this device.
 *
 * @return A list of locations this device has been recorded to be at.
 *
 * TODO(lerner): Use a set instead. Hashcode is always 0 on my serializable
 * locations though, and they're not comparable, so we can't use HashSet or TreeSet.
 */
public List<SerializableLocation> getAllLocations() throws StreamCorruptedException,
    OptionalDataException, IOException, ClassNotFoundException {
  if (getMostRecentSequenceNumber() == NO_SEQUENCE_STORED) {
    return new ArrayList<SerializableLocation>();
  }

  return getLocations(MIN_SEQUENCE_NUMBER, getMostRecentSequenceNumber());
}
 
开发者ID:casific,项目名称:murmur,代码行数:17,代码来源:LocationStore.java

示例14: getLocations

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Get a list of locations stored on this device between the given indexes (inclusive).
 * Throws an IllegalArgumentException if either index value is out of bounds
 * or end is less than start.
 *
 * @return A list of locations this device has been recorded to be at.
 */
public List<SerializableLocation> getLocations(int start, int end) throws StreamCorruptedException,
    OptionalDataException, IOException, ClassNotFoundException {
  int lastSequenceNumber = getMostRecentSequenceNumber();
  if (start < MIN_SEQUENCE_NUMBER || end < MIN_SEQUENCE_NUMBER ||
      start > lastSequenceNumber || end > lastSequenceNumber || end < start) {
    throw new IllegalArgumentException("Indexes [" + start + "," + end + "] out of bounds.");
  }

  ArrayList<SerializableLocation> locations = new ArrayList<SerializableLocation>();
  for (int i = start; i <= end; i++) {
    locations.add((SerializableLocation) store.getObject(getLocationKey(i)));
  }
  return locations;
}
 
开发者ID:casific,项目名称:murmur,代码行数:22,代码来源:LocationStore.java

示例15: putObject

import java.io.OptionalDataException; //导入依赖的package包/类
/**
 * Stores the given object in the Murmur generic store, using Java's object
 * serialization and base64 coding.
 *
 * @param key   The key under which to store the data.
 * @param value The object to store, which must be serializable.
 */
public void putObject(String key, Object value) throws IOException,
        StreamCorruptedException, OptionalDataException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream o = new ObjectOutputStream(b);
    o.writeObject(value);
    o.close();

    put(key, new String(Base64.encode(b.toByteArray(), Base64.DEFAULT)));
}
 
开发者ID:casific,项目名称:murmur,代码行数:17,代码来源:StorageBase.java


注:本文中的java.io.OptionalDataException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。