本文整理汇总了Java中org.apache.http.MalformedChunkCodingException类的典型用法代码示例。如果您正苦于以下问题:Java MalformedChunkCodingException类的具体用法?Java MalformedChunkCodingException怎么用?Java MalformedChunkCodingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MalformedChunkCodingException类属于org.apache.http包,在下文中一共展示了MalformedChunkCodingException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextChunk
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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;
}
}
示例2: nextChunk
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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();
}
}
示例3: getChunkSize
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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");
}
}
示例4: parseTrailerHeaders
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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;
}
}
示例5: getChunkSize
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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");
}
}
示例6: parseTrailerHeaders
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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;
}
}
示例7: testMalformedChunkException
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
@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);
}
示例8: close
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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
}
}
示例9: getLocalizedMessage
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
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;
}
示例10: testColumnValueTooLargeForBuffer
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
@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);
}
示例11: getChunkSize
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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");
}
}
示例12: parseTrailerHeaders
import org.apache.http.MalformedChunkCodingException; //导入依赖的package包/类
/**
* 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;
}
}