Java 类org.apache.http.MalformedChunkCodingException 实例源码

项目:docker-java    文件:ChunkedInputStream.java   
/**
 * Read the next chunk.
 * @throws IOException in case of an I/O error
 */
private void nextChunk() throws IOException {
    if (state == CHUNK_INVALID) {
        throw new MalformedChunkCodingException("Corrupt data stream");
    }
    try {
        chunkSize = getChunkSize();
        if (chunkSize < 0L) {
            throw new MalformedChunkCodingException("Negative chunk size");
        }
        state = CHUNK_DATA;
        pos = 0L;
        if (chunkSize == 0L) {
            eof = true;
            parseTrailerHeaders();
        }
    } catch (MalformedChunkCodingException ex) {
        state = CHUNK_INVALID;
        throw ex;
    }
}
项目:lams    文件:ChunkedInputStream.java   
/**
 * Read the next chunk.
 * @throws IOException in case of an I/O error
 */
private void nextChunk() throws IOException {
    chunkSize = getChunkSize();
    if (chunkSize < 0) {
        throw new MalformedChunkCodingException("Negative chunk size");
    }
    state = CHUNK_DATA;
    pos = 0;
    if (chunkSize == 0) {
        eof = true;
        parseTrailerHeaders();
    }
}
项目:lams    文件:ChunkedInputStream.java   
/**
 * Expects the stream to start with a chunksize in hex with optional
 * comments after a semicolon. The line must end with a CRLF: "a3; some
 * comment\r\n" Positions the stream at the start of the next line.
 *
 * @param in The new input stream.
 * @param required <tt>true<tt/> if a valid chunk must be present,
 *                 <tt>false<tt/> otherwise.
 *
 * @return the chunk size as integer
 *
 * @throws IOException when the chunk size could not be parsed
 */
private int getChunkSize() throws IOException {
    int st = this.state;
    switch (st) {
    case CHUNK_CRLF:
        this.buffer.clear();
        int i = this.in.readLine(this.buffer);
        if (i == -1) {
            return 0;
        }
        if (!this.buffer.isEmpty()) {
            throw new MalformedChunkCodingException(
                "Unexpected content at the end of chunk");
        }
        state = CHUNK_LEN;
        //$FALL-THROUGH$
    case CHUNK_LEN:
        this.buffer.clear();
        i = this.in.readLine(this.buffer);
        if (i == -1) {
            return 0;
        }
        int separator = this.buffer.indexOf(';');
        if (separator < 0) {
            separator = this.buffer.length();
        }
        try {
            return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
        } catch (NumberFormatException e) {
            throw new MalformedChunkCodingException("Bad chunk header");
        }
    default:
        throw new IllegalStateException("Inconsistent codec state");
    }
}
项目:lams    文件:ChunkedInputStream.java   
/**
 * Reads and stores the Trailer headers.
 * @throws IOException in case of an I/O error
 */
private void parseTrailerHeaders() throws IOException {
    try {
        this.footers = AbstractMessageParser.parseHeaders
            (in, -1, -1, null);
    } catch (HttpException ex) {
        IOException ioe = new MalformedChunkCodingException("Invalid footer: "
                + ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }
}
项目:remote-files-sync    文件:ChunkedInputStreamHC4.java   
/**
 * Read the next chunk.
 * @throws IOException in case of an I/O error
 */
private void nextChunk() throws IOException {
    chunkSize = getChunkSize();
    if (chunkSize < 0) {
        throw new MalformedChunkCodingException("Negative chunk size");
    }
    state = CHUNK_DATA;
    pos = 0;
    if (chunkSize == 0) {
        eof = true;
        parseTrailerHeaders();
    }
}
项目:remote-files-sync    文件:ChunkedInputStreamHC4.java   
/**
 * Expects the stream to start with a chunksize in hex with optional
 * comments after a semicolon. The line must end with a CRLF: "a3; some
 * comment\r\n" Positions the stream at the start of the next line.
 */
private int getChunkSize() throws IOException {
    final int st = this.state;
    switch (st) {
    case CHUNK_CRLF:
        this.buffer.clear();
        final int bytesRead1 = this.in.readLine(this.buffer);
        if (bytesRead1 == -1) {
            return 0;
        }
        if (!this.buffer.isEmpty()) {
            throw new MalformedChunkCodingException(
                "Unexpected content at the end of chunk");
        }
        state = CHUNK_LEN;
        //$FALL-THROUGH$
    case CHUNK_LEN:
        this.buffer.clear();
        final int bytesRead2 = this.in.readLine(this.buffer);
        if (bytesRead2 == -1) {
            return 0;
        }
        int separator = this.buffer.indexOf(';');
        if (separator < 0) {
            separator = this.buffer.length();
        }
        try {
            return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
        } catch (final NumberFormatException e) {
            throw new MalformedChunkCodingException("Bad chunk header");
        }
    default:
        throw new IllegalStateException("Inconsistent codec state");
    }
}
项目:remote-files-sync    文件:ChunkedInputStreamHC4.java   
/**
 * Reads and stores the Trailer headers.
 * @throws IOException in case of an I/O error
 */
private void parseTrailerHeaders() throws IOException {
    try {
        this.footers = AbstractMessageParserHC4.parseHeaders
            (in, -1, -1, null);
    } catch (final HttpException ex) {
        final IOException ioe = new MalformedChunkCodingException("Invalid footer: "
                + ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }
}
项目:emodb    文件:JsonStreamingArrayParserTest.java   
@Test
@SuppressWarnings("unchecked")
public void testMalformedChunkException() throws Exception {
    InputSupplier<InputStream> input = ByteStreams.join(
            ByteStreams.newInputStreamSupplier("[5,6".getBytes(Charsets.UTF_8)),
            exceptionStreamSupplier(new MalformedChunkCodingException("Bad chunk header")));
    assertThrowsEOFException(input.getInput(), Integer.class);
}
项目:nomad-java-sdk    文件:FramedStream.java   
/**
 * Closes the stream and frees the underlying HTTP connection.
 *
 * @throws IOException if an error is encountered while trying to close the stream.
 */
@Override
public void close() throws IOException {
    try {
        // We need to first close the response directly rather than the parser or the response entity's
        // InputStream in order to avoid a long delay.
        response.close();
    } catch (MalformedChunkCodingException e) {
        // that's because we forced the stream closed
    }
}
项目:Visit    文件:ChunkedInputStreamHC4.java   
/**
 * Read the next chunk.
 * @throws IOException in case of an I/O error
 */
private void nextChunk() throws IOException {
    chunkSize = getChunkSize();
    if (chunkSize < 0) {
        throw new MalformedChunkCodingException("Negative chunk size");
    }
    state = CHUNK_DATA;
    pos = 0;
    if (chunkSize == 0) {
        eof = true;
        parseTrailerHeaders();
    }
}
项目:Visit    文件:ChunkedInputStreamHC4.java   
/**
 * Expects the stream to start with a chunksize in hex with optional
 * comments after a semicolon. The line must end with a CRLF: "a3; some
 * comment\r\n" Positions the stream at the start of the next line.
 */
private int getChunkSize() throws IOException {
    final int st = this.state;
    switch (st) {
    case CHUNK_CRLF:
        this.buffer.clear();
        final int bytesRead1 = this.in.readLine(this.buffer);
        if (bytesRead1 == -1) {
            return 0;
        }
        if (!this.buffer.isEmpty()) {
            throw new MalformedChunkCodingException(
                "Unexpected content at the end of chunk");
        }
        state = CHUNK_LEN;
        //$FALL-THROUGH$
    case CHUNK_LEN:
        this.buffer.clear();
        final int bytesRead2 = this.in.readLine(this.buffer);
        if (bytesRead2 == -1) {
            return 0;
        }
        int separator = this.buffer.indexOf(';');
        if (separator < 0) {
            separator = this.buffer.length();
        }
        try {
            return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
        } catch (final NumberFormatException e) {
            throw new MalformedChunkCodingException("Bad chunk header");
        }
    default:
        throw new IllegalStateException("Inconsistent codec state");
    }
}
项目:Visit    文件:ChunkedInputStreamHC4.java   
/**
 * Reads and stores the Trailer headers.
 * @throws IOException in case of an I/O error
 */
private void parseTrailerHeaders() throws IOException {
    try {
        this.footers = AbstractMessageParserHC4.parseHeaders
            (in, -1, -1, null);
    } catch (final HttpException ex) {
        final IOException ioe = new MalformedChunkCodingException("Invalid footer: "
                + ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }
}
项目:4pdaClient-plus    文件:AppLog.java   
public static String getLocalizedMessage(Throwable ex, String defaultValue) {
    if (isHostUnavailableException(ex))
        return App.getContext().getString(R.string.server_not_available_or_not_respond);
    if (isTimeOutException(ex))
        return App.getContext().getString(R.string.exceeded_timeout);
    if (isException(ex, MalformedChunkCodingException.class))
        return App.getContext().getString(R.string.server_failed_to_respond);
    if (isException(ex, SocketException.class))
        return App.getContext().getString(R.string.connection_lost);
    return defaultValue;
}
项目:questdb    文件:QueryHandlerSmallBufferTest.java   
@Test(expected = MalformedChunkCodingException.class)
public void testColumnValueTooLargeForBuffer() throws Exception {
    StringBuilder allChars = new StringBuilder();
    for (char c = Character.MIN_VALUE; c < 0xD800; c++) { //
        allChars.append(c);
    }

    String allCharString = allChars.toString();
    QueryHandlerTest.generateJournal("xyz", allCharString, 4.900232E-10, 2.598E20, Long.MAX_VALUE, Integer.MIN_VALUE, new Timestamp(-102023));
    String query = "select x, id from xyz \n limit 1";
    QueryHandlerTest.download(query, temp);
}
项目:docker-java    文件:ChunkedInputStream.java   
/**
 * Expects the stream to start with a chunksize in hex with optional
 * comments after a semicolon. The line must end with a CRLF: "a3; some
 * comment\r\n" Positions the stream at the start of the next line.
 */
private long getChunkSize() throws IOException {
    final int st = this.state;
    switch (st) {
    case CHUNK_CRLF:
        this.buffer.clear();
        final int bytesRead1 = this.in.readLine(this.buffer);
        if (bytesRead1 == -1) {
            throw new MalformedChunkCodingException(
                "CRLF expected at end of chunk");
        }
        if (!this.buffer.isEmpty()) {
            throw new MalformedChunkCodingException(
                "Unexpected content at the end of chunk");
        }
        state = CHUNK_LEN;
        //$FALL-THROUGH$
    case CHUNK_LEN:
        this.buffer.clear();
        final int bytesRead2 = this.in.readLine(this.buffer);
        if (bytesRead2 == -1) {
            throw new ConnectionClosedException("Premature end of chunk coded message body: " +
                    "closing chunk expected");
        }
        int separator = this.buffer.indexOf(';');
        if (separator < 0) {
            separator = this.buffer.length();
        }
        final String s = this.buffer.substringTrimmed(0, separator);
        try {
            return Long.parseLong(s, 16);
        } catch (final NumberFormatException e) {
            throw new MalformedChunkCodingException("Bad chunk header: " + s);
        }
    default:
        throw new IllegalStateException("Inconsistent codec state");
    }
}
项目:docker-java    文件:ChunkedInputStream.java   
/**
 * Reads and stores the Trailer headers.
 * @throws IOException in case of an I/O error
 */
private void parseTrailerHeaders() throws IOException {
    try {
        this.footers = AbstractMessageParser.parseHeaders(in,
                constraints.getMaxHeaderCount(),
                constraints.getMaxLineLength(),
                null);
    } catch (final HttpException ex) {
        final IOException ioe = new MalformedChunkCodingException("Invalid footer: "
                + ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }
}
项目:ZTLib    文件:ChunkedInputStreamHC4.java   
/**
 * Read the next chunk.
 * @throws IOException in case of an I/O error
 */
private void nextChunk() throws IOException {
    chunkSize = getChunkSize();
    if (chunkSize < 0) {
        throw new MalformedChunkCodingException("Negative chunk size");
    }
    state = CHUNK_DATA;
    pos = 0;
    if (chunkSize == 0) {
        eof = true;
        parseTrailerHeaders();
    }
}
项目:ZTLib    文件:ChunkedInputStreamHC4.java   
/**
 * Expects the stream to start with a chunksize in hex with optional
 * comments after a semicolon. The line must end with a CRLF: "a3; some
 * comment\r\n" Positions the stream at the start of the next line.
 */
private int getChunkSize() throws IOException {
    final int st = this.state;
    switch (st) {
    case CHUNK_CRLF:
        this.buffer.clear();
        final int bytesRead1 = this.in.readLine(this.buffer);
        if (bytesRead1 == -1) {
            return 0;
        }
        if (!this.buffer.isEmpty()) {
            throw new MalformedChunkCodingException(
                "Unexpected content at the end of chunk");
        }
        state = CHUNK_LEN;
        //$FALL-THROUGH$
    case CHUNK_LEN:
        this.buffer.clear();
        final int bytesRead2 = this.in.readLine(this.buffer);
        if (bytesRead2 == -1) {
            return 0;
        }
        int separator = this.buffer.indexOf(';');
        if (separator < 0) {
            separator = this.buffer.length();
        }
        try {
            return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
        } catch (final NumberFormatException e) {
            throw new MalformedChunkCodingException("Bad chunk header");
        }
    default:
        throw new IllegalStateException("Inconsistent codec state");
    }
}
项目:ZTLib    文件:ChunkedInputStreamHC4.java   
/**
 * Reads and stores the Trailer headers.
 * @throws IOException in case of an I/O error
 */
private void parseTrailerHeaders() throws IOException {
    try {
        this.footers = AbstractMessageParserHC4.parseHeaders
            (in, -1, -1, null);
    } catch (final HttpException ex) {
        final IOException ioe = new MalformedChunkCodingException("Invalid footer: "
                + ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }
}