Search in sources :

Example 1 with SoftEndOfStreamException

use of org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException in project spring-integration by spring-projects.

the class RFC6587SyslogDeserializer method deserialize.

@Override
public Map<String, ?> deserialize(InputStream inputStream) throws IOException {
    DataInputStream stream = new DataInputStream(inputStream);
    String line;
    int octetCount = 0;
    boolean shortRead = false;
    int peek = stream.read();
    if (isDigit(peek)) {
        octetCount = calculateLength(stream, peek);
        Assert.state(octetCount > 0, "Expected length > 0");
        byte[] bytes = new byte[octetCount];
        try {
            stream.readFully(bytes);
        } catch (EOFException e) {
            shortRead = true;
        }
        line = new String(bytes, getCharset());
    } else if (peek == '<') {
        byte[] bytes = this.delimitedDeserializer.deserialize(inputStream);
        line = "<" + new String(bytes, getCharset());
    } else if (peek < 0) {
        throw new SoftEndOfStreamException();
    } else {
        throw new IllegalStateException("Expected a digit or '<', got 0x" + Integer.toHexString(peek));
    }
    return this.parser.parse(line, octetCount, shortRead);
}
Also used : SoftEndOfStreamException(org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException) EOFException(java.io.EOFException) DataInputStream(java.io.DataInputStream)

Aggregations

DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 SoftEndOfStreamException (org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException)1