當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletInputStream.readLine方法代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:RunCommand.java


注:本文中的javax.servlet.ServletInputStream.readLine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。