Search in sources :

Example 16 with StreamCorruptedException

use of java.io.StreamCorruptedException in project jdk8u_jdk by JetBrains.

the class StreamRemoteCall method getResultStream.

/**
     * 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());
    // transport op
    wr.writeByte(TransportConstants.Return);
    // creates a MarshalOutputStream
    getOutputStream(true);
    // return header, part 2 (read by client-side RemoteCall)
    if (//
    success)
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    // write id for gcAck
    out.writeID();
    return out;
}
Also used : DataOutputStream(java.io.DataOutputStream) StreamCorruptedException(java.io.StreamCorruptedException)

Example 17 with StreamCorruptedException

use of java.io.StreamCorruptedException in project midpoint by Evolveum.

the class PropertyComplexValueFilterType method copyOf.

/**
     * Creates and returns a deep copy of a given {@code Serializable}.
     * 
     * @param serializable
     *     The instance to copy or {@code null}.
     * @return
     *     A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
     */
private static Serializable copyOf(final Serializable serializable) {
    // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
    if (serializable != null) {
        try {
            final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
            final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
            out.writeObject(serializable);
            out.close();
            final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
            final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
            final Serializable copy = ((Serializable) in.readObject());
            in.close();
            return copy;
        } catch (SecurityException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (ClassNotFoundException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (InvalidClassException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (NotSerializableException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (StreamCorruptedException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (OptionalDataException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (IOException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 18 with StreamCorruptedException

use of java.io.StreamCorruptedException in project midpoint by Evolveum.

the class QueryType method copyOf.

/**
     * Creates and returns a deep copy of a given {@code Serializable}.
     * 
     * @param serializable
     *     The instance to copy or {@code null}.
     * @return
     *     A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
     */
private static Serializable copyOf(final Serializable serializable) {
    // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
    if (serializable != null) {
        try {
            final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
            final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
            out.writeObject(serializable);
            out.close();
            final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
            final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
            final Serializable copy = ((Serializable) in.readObject());
            in.close();
            return copy;
        } catch (SecurityException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (ClassNotFoundException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (InvalidClassException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (NotSerializableException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (StreamCorruptedException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (OptionalDataException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (IOException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 19 with StreamCorruptedException

use of java.io.StreamCorruptedException in project adempiere by adempiere.

the class ConcreteElement method clone.

/**
	 * Allows all Elements the ability to be cloned.
	 */
public Object clone() {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(baos);
        out.writeObject(this);
        out.close();
        ByteArrayInputStream bin = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream in = new ObjectInputStream(bin);
        Object clone = in.readObject();
        in.close();
        return (clone);
    } catch (ClassNotFoundException cnfe) {
        throw new InternalError(cnfe.toString());
    } catch (StreamCorruptedException sce) {
        throw new InternalError(sce.toString());
    } catch (IOException ioe) {
        throw new InternalError(ioe.toString());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 20 with StreamCorruptedException

use of java.io.StreamCorruptedException in project geode by apache.

the class TcpServer method processRequest.

/**
   * fix for bug 33711 - client requests are spun off to another thread for processing. Requests are
   * synchronized in processGossip.
   */
private void processRequest(final Socket sock) {
    executor.execute(() -> {
        long startTime = DistributionStats.getStatTime();
        DataInputStream input = null;
        Object request, response;
        try {
            socketCreator.configureServerSSLSocket(sock);
            sock.setSoTimeout(READ_TIMEOUT);
            try {
                input = new DataInputStream(sock.getInputStream());
            } catch (StreamCorruptedException e) {
                // Some garbage can be left on the socket stream
                // if a peer disappears at exactly the wrong moment.
                log.debug("Discarding illegal request from " + (sock.getInetAddress().getHostAddress() + ":" + sock.getPort()), e);
                return;
            }
            int gossipVersion = readGossipVersion(sock, input);
            short versionOrdinal;
            if (gossipVersion <= getCurrentGossipVersion() && GOSSIP_TO_GEMFIRE_VERSION_MAP.containsKey(gossipVersion)) {
                // Create a versioned stream to remember sender's GemFire version
                versionOrdinal = (short) GOSSIP_TO_GEMFIRE_VERSION_MAP.get(gossipVersion);
            } else {
                // Close the socket. We can not accept requests from a newer version
                try {
                    sock.getOutputStream().write("unknown protocol version".getBytes());
                    sock.getOutputStream().flush();
                } catch (IOException e) {
                    log.debug("exception in sending reply to process using unknown protocol " + gossipVersion, e);
                }
                sock.close();
                return;
            }
            if (Version.GFE_71.compareTo(versionOrdinal) <= 0) {
                // Recent versions of TcpClient will send the version ordinal
                versionOrdinal = input.readShort();
            }
            if (log.isDebugEnabled() && versionOrdinal != Version.CURRENT_ORDINAL) {
                log.debug("Locator reading request from " + sock.getInetAddress() + " with version " + Version.fromOrdinal(versionOrdinal, false));
            }
            input = new VersionedDataInputStream(input, Version.fromOrdinal(versionOrdinal, false));
            request = DataSerializer.readObject(input);
            if (log.isDebugEnabled()) {
                log.debug("Locator received request " + request + " from " + sock.getInetAddress());
            }
            if (request instanceof ShutdownRequest) {
                shuttingDown = true;
                // Don't call shutdown from within the worker thread, see java bug #6576792.
                // Closing the socket will cause our acceptor thread to shutdown the executor
                this.serverSocketPortAtClose = srv_sock.getLocalPort();
                srv_sock.close();
                response = new ShutdownResponse();
            } else if (request instanceof InfoRequest) {
                response = handleInfoRequest(request);
            } else if (request instanceof VersionRequest) {
                response = handleVersionRequest(request);
            } else {
                response = handler.processRequest(request);
            }
            handler.endRequest(request, startTime);
            startTime = DistributionStats.getStatTime();
            if (response != null) {
                DataOutputStream output = new DataOutputStream(sock.getOutputStream());
                if (versionOrdinal != Version.CURRENT_ORDINAL) {
                    output = new VersionedDataOutputStream(output, Version.fromOrdinal(versionOrdinal, false));
                }
                DataSerializer.writeObject(response, output);
                output.flush();
            }
            handler.endResponse(request, startTime);
        } catch (EOFException ignore) {
        // client went away - ignore
        } catch (CancelException ignore) {
        // ignore
        } catch (ClassNotFoundException ex) {
            String sender = null;
            if (sock != null) {
                sender = sock.getInetAddress().getHostAddress();
            }
            log.info("Unable to process request from " + sender + " exception=" + ex.getMessage());
        } catch (Exception ex) {
            String sender = null;
            if (sock != null) {
                sender = sock.getInetAddress().getHostAddress();
            }
            if (ex instanceof IOException) {
                // log with severe.
                if (!sock.isClosed()) {
                    log.info("Exception in processing request from " + sender, ex);
                }
            } else {
                log.fatal("Exception in processing request from " + sender, ex);
            }
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            throw err;
        } catch (Throwable ex) {
            SystemFailure.checkFailure();
            String sender = null;
            if (sock != null) {
                sender = sock.getInetAddress().getHostAddress();
            }
            try {
                log.fatal("Exception in processing request from " + sender, ex);
            } catch (VirtualMachineError err) {
                SystemFailure.initiateFailure(err);
                throw err;
            } catch (Throwable t) {
                SystemFailure.checkFailure();
                t.printStackTrace();
            }
        } finally {
            try {
                sock.close();
            } catch (IOException ignore) {
            // ignore
            }
        }
    });
}
Also used : DataOutputStream(java.io.DataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) CancelException(org.apache.geode.CancelException) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) EOFException(java.io.EOFException) SSLException(javax.net.ssl.SSLException) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) EOFException(java.io.EOFException) StreamCorruptedException(java.io.StreamCorruptedException) CancelException(org.apache.geode.CancelException) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream)

Aggregations

StreamCorruptedException (java.io.StreamCorruptedException)20 ObjectInputStream (java.io.ObjectInputStream)15 IOException (java.io.IOException)14 ByteArrayInputStream (java.io.ByteArrayInputStream)11 OptionalDataException (java.io.OptionalDataException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InvalidClassException (java.io.InvalidClassException)5 ObjectOutputStream (java.io.ObjectOutputStream)5 NotSerializableException (java.io.NotSerializableException)4 Serializable (java.io.Serializable)4 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 DataOutputStream (java.io.DataOutputStream)2 EOFException (java.io.EOFException)2 File (java.io.File)2 Sample (edu.berkeley.cs.amplab.carat.thrift.Sample)1 DataInputStream (java.io.DataInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ObjectStreamClass (java.io.ObjectStreamClass)1 BufferUnderflowException (java.nio.BufferUnderflowException)1