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


Java BufferedReader.read方法代碼示例

本文整理匯總了Java中java.io.BufferedReader.read方法的典型用法代碼示例。如果您正苦於以下問題:Java BufferedReader.read方法的具體用法?Java BufferedReader.read怎麽用?Java BufferedReader.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.BufferedReader的用法示例。


在下文中一共展示了BufferedReader.read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getReaderString

import java.io.BufferedReader; //導入方法依賴的package包/類
public static String getReaderString(BufferedReader reader) {
  StringBuffer out = new StringBuffer();
  char[] c = new char[8192];
  try {
    for (int n; (n = reader.read(c, 0, c.length)) != -1;) {
      out.append(c, 0, n);
    }
    reader.close();
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
  return out.toString();
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:15,代碼來源:BetterFile.java

示例2: testOpenBufferedStream

import java.io.BufferedReader; //導入方法依賴的package包/類
public void testOpenBufferedStream() throws IOException {
  BufferedReader reader = source.openBufferedStream();
  assertTrue(source.wasStreamOpened());
  assertFalse(source.wasStreamClosed());

  StringWriter writer = new StringWriter();
  char[] buf = new char[64];
  int read;
  while ((read = reader.read(buf)) != -1) {
    writer.write(buf, 0, read);
  }
  reader.close();
  writer.close();

  assertTrue(source.wasStreamClosed());
  assertEquals(STRING, writer.toString());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:CharSourceTest.java

示例3: writeBinaryStream

import java.io.BufferedReader; //導入方法依賴的package包/類
/**
 * Writes a stream of uninterpreted bytes to this <code>SQLOutputImpl</code>
 * object.
 *
 * @param x the value to pass to the database
 * @throws SQLException if the <code>SQLOutputImpl</code> object is in
 *        use by a <code>SQLData</code> object attempting to write the attribute
 *        values of a UDT to the database.
 */
@SuppressWarnings("unchecked")
public void writeBinaryStream(java.io.InputStream x) throws SQLException {
     BufferedReader bufReader = new BufferedReader(new InputStreamReader(x));
     try {
           int i;
         while( (i=bufReader.read()) != -1 ) {
            char ch = (char)i;

            StringBuffer strBuf = new StringBuffer();
            strBuf.append(ch);

            String str = new String(strBuf);
            String strLine = bufReader.readLine();

            writeString(str.concat(strLine));
         }
    } catch(IOException ioe) {
        throw new SQLException(ioe.getMessage());
    }
}
 
開發者ID:madHEYsia,項目名稱:ClassroomFlipkart,代碼行數:30,代碼來源:SQLOutputImpl.java

示例4: readFileToString

import java.io.BufferedReader; //導入方法依賴的package包/類
private static String readFileToString(String filePath) {
	StringBuilder fileData = new StringBuilder(1000);
	try {
		BufferedReader reader = new BufferedReader(new FileReader(filePath));

		char[] buf = new char[10];
		int numRead = 0;
		while ((numRead = reader.read(buf)) != -1) {
			String readData = String.valueOf(buf, 0, numRead);
			fileData.append(readData);
			buf = new char[1024];
		}
		reader.close();
	}
	catch(IOException e) {
		e.printStackTrace();
	}
	return fileData.toString();	
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:20,代碼來源:JavaSourceParser.java

示例5: writeCharacterStream

import java.io.BufferedReader; //導入方法依賴的package包/類
/**
 * Writes a stream of Unicode characters to this
 * <code>SQLOutputImpl</code> object. The driver will do any necessary
 * conversion from Unicode to the database <code>CHAR</code> format.
 *
 * @param x the value to pass to the database
 * @throws SQLException if the <code>SQLOutputImpl</code> object is in
 *        use by a <code>SQLData</code> object attempting to write the attribute
 *        values of a UDT to the database.
 */
@SuppressWarnings("unchecked")
public void writeCharacterStream(java.io.Reader x) throws SQLException {
     BufferedReader bufReader = new BufferedReader(x);
     try {
         int i;
         while( (i = bufReader.read()) != -1 ) {
            char ch = (char)i;
            StringBuffer strBuf = new StringBuffer();
            strBuf.append(ch);

            String str = new String(strBuf);
            String strLine = bufReader.readLine();

            writeString(str.concat(strLine));
         }
     } catch(IOException ioe) {

     }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:SQLOutputImpl.java

示例6: consumeResponse

import java.io.BufferedReader; //導入方法依賴的package包/類
private String consumeResponse(InputStream inputStr, Charset encoding) {
  StringBuilder body = new StringBuilder();
  BufferedReader reader = new BufferedReader(new InputStreamReader(inputStr, encoding));
  try {
    int i;
    char[] cbuf = new char[BUFFER_SIZE];
    while ((i = reader.read(cbuf)) > 0) {
      if (body == null) {
        continue;
      }
      if (body.length() + i >= MAX_RESP_LENGTH) {
        body = null;
      } else {
        body.append(cbuf, 0, i);
      }
    }
  } catch (IOException e) {
    LOGGER.error("Error reading response", e);
  }
  return body == null ? "Response too long" : body.toString();
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:22,代碼來源:ApptuitPutClient.java

示例7: getFileContent

import java.io.BufferedReader; //導入方法依賴的package包/類
private String getFileContent(File f) throws IOException {
    BufferedReader br = new BufferedReader(new FileReader(f));
    char[] buffer = new char[1024];
    int read = br.read(buffer);
    String t = new String(buffer, 0, read);
    String ls = System.getProperty("line.separator");
    return t.replace(ls, "\n");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:LineDiffTest.java

示例8: printLines

import java.io.BufferedReader; //導入方法依賴的package包/類
private void printLines(InputStream ins) throws IOException {
    int line;
    BufferedReader in = new BufferedReader(
            new InputStreamReader(ins));
    while ((line = in.read()) != -1) {
        consoleOutputStream.write(line);
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:9,代碼來源:InjectScript.java

示例9: toJpaNoValues

import java.io.BufferedReader; //導入方法依賴的package包/類
@Test
public void toJpaNoValues() throws Exception {
	final BufferedReader bufferedReader = new BufferedReader(new StringReader("\n"), 1);
	bufferedReader.read();
	final List<DummyEntity> jpa = csvForJpa.toJpa(DummyEntity.class, bufferedReader, false);
	Assert.assertTrue(jpa.isEmpty());
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:8,代碼來源:CsvForJpaTest.java

示例10: sendToUrl

import java.io.BufferedReader; //導入方法依賴的package包/類
public static String sendToUrl(final URL url, final String data, int connectTimeout) throws IOException
{
    final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        
        urlConnection.setConnectTimeout(connectTimeout);
        urlConnection.setReadTimeout(READ_TIMEOUT);
        
        urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        urlConnection.setRequestProperty("Accept", "application/json");
        
        final byte[] bytes = data.getBytes(Charset.forName("UTF-8"));
        urlConnection.setFixedLengthStreamingMode(bytes.length);
        urlConnection.getOutputStream().write(bytes);
        
        final StringBuilder stringBuilder = new StringBuilder();
        final BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
        int read;
        final char[] chars = new char[1024];
        while ((read = reader.read(chars)) != -1)
            stringBuilder.append(chars, 0, read);
        return stringBuilder.toString();
    } finally {
        urlConnection.disconnect();
    }
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:29,代碼來源:JSONParser.java

示例11: readChars

import java.io.BufferedReader; //導入方法依賴的package包/類
private static String readChars(FileObject fo, Charset set) throws IOException {
    CharBuffer arr = CharBuffer.allocate((int)fo.getSize() * 2);
    BufferedReader r = new BufferedReader(new InputStreamReader(fo.getInputStream(), set));
    while (r.read(arr) != -1) {
        // again
    }
    r.close();
    
    arr.flip();
    return arr.toString();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:SCFTHandlerTest.java

示例12: parseNumber

import java.io.BufferedReader; //導入方法依賴的package包/類
static JNumber parseNumber(BufferedReader reader) throws IOException {
    skipSpace(reader);
    StringBuilder sb = new StringBuilder();
    while (true) {
    	reader.mark(1);
        int c = reader.read();
        if (c >= '0' && c <= '9' || c == '.' || c == '-') {
            sb.append((char)c);
        } else {
        	reader.reset();
            break;
        }
    }
    return new JNumber(Double.parseDouble(sb.toString()));
}
 
開發者ID:DNAProject,項目名稱:DNASDKJava,代碼行數:16,代碼來源:JNumber.java

示例13: readerToString

import java.io.BufferedReader; //導入方法依賴的package包/類
/**
 * Wrap reader into buffered one and start reading returning
 * String as a EOF is reached.
 */
public static String readerToString(Reader reader) throws IOException {
    
    BufferedReader fastReader = new BufferedReader(reader);
    StringBuffer buf = new StringBuffer(1024);
    try {
        for (int i = fastReader.read(); i >= 0; i = fastReader.read()) {
            buf.append((char)i);                            
        }
    } catch (EOFException eof) {
        //expected
    }

    return buf.toString();        
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:Convertors.java

示例14: getFrameworkUsage

import java.io.BufferedReader; //導入方法依賴的package包/類
/**
 * Gets the framework usage as a formatted string.
 *
 * @return - The framework usage as string to be printed to console via
 * System.out.print()
 */
public static String getFrameworkUsage() {
    try {
        InputStream is = Info.class.getClass().getResourceAsStream("/screenframework/com/zilabs/frameworkinfo/usage");
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        sb.setLength(0);
        while (br.read() > 1) {
            sb.append(br.readLine());
            sb.append("\n");
        }
    } catch (IOException e) {
        return e.getMessage();
    }
    return sb.toString();
}
 
開發者ID:karanja-simon,項目名稱:MultiScreenFramework,代碼行數:21,代碼來源:Info.java

示例15: testOpenBufferedStream

import java.io.BufferedReader; //導入方法依賴的package包/類
public void testOpenBufferedStream() throws IOException {
  BufferedReader reader = source.openBufferedStream();

  StringWriter writer = new StringWriter();
  char[] buf = new char[64];
  int read;
  while ((read = reader.read(buf)) != -1) {
    writer.write(buf, 0, read);
  }
  reader.close();
  writer.close();

  assertExpectedString(writer.toString());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:15,代碼來源:CharSourceTester.java


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