當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。