本文整理匯總了Java中javax.servlet.ServletInputStream.readLine方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletInputStream.readLine方法的具體用法?Java ServletInputStream.readLine怎麽用?Java ServletInputStream.readLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.ServletInputStream
的用法示例。
在下文中一共展示了ServletInputStream.readLine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import javax.servlet.ServletInputStream; //導入方法依賴的package包/類
/**
* Reads a line into the specified byte array. The data is read until a newline
* character is encountered (all of "\n", "\r", "\n\r", "\r\n" are considered a
* newline character) or a maximum number of bytes is read. Thus the clients
* should not expect the result to be always a complete line. The amximum number
* of bytes is dictated by the length of the byte array.
*
* This wrapper is introduced in order not to return -1, when a line cannot be
* read, but to throw an IOException instead, since this situation is erroneous
* anyway.
*
* @param input
* A ServletInputStream from which to read data.
* @param buffer
* A byte array where to put the data
* @throws java.io.IOException
* If an I/O error happens.
* @return
* The number of bytes read.
*/
private int read(ServletInputStream input, byte[] buffer) throws IOException {
int length = input.readLine(buffer, 0, buffer.length);
if (length == -1) {
throw new IOException("Could not read a complete " +
"buffer without reaching an EOL or reached " +
"the end of stream prematurely");
}
return length;
}