本文整理匯總了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();
}
示例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());
}
示例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());
}
}
示例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();
}
示例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) {
}
}
示例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();
}
示例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");
}
示例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);
}
}
示例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());
}
示例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();
}
}
示例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();
}
示例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()));
}
示例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();
}
示例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();
}
示例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());
}