当前位置: 首页>>代码示例>>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;未经允许,请勿转载。