本文整理了Java中java.io.BufferedReader.read()
方法的一些代码示例,展示了BufferedReader.read()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedReader.read()
方法的具体详情如下:
包路径:java.io.BufferedReader
类名称:BufferedReader
方法名:read
[英]Reads a single character from this reader and returns it with the two higher-order bytes set to 0. If possible, BufferedReader returns a character from the buffer. If there are no characters available in the buffer, it fills the buffer and then returns a character. It returns -1 if there are no more characters in the source reader.
[中]从该读取器读取单个字符,并返回它,其中两个高阶字节设置为0。如果可能,BufferedReader将从缓冲区返回一个字符。如果缓冲区中没有可用字符,它将填充缓冲区,然后返回一个字符。如果源读取器中没有更多字符,则返回-1。
代码示例来源:origin: stackoverflow.com
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.forName("ISO-8859-1")),1024);
// ...
// inside some iteration / processing logic:
if (br.ready()) {
int readCount = br.read(inputData, bufferOffset, inputData.length-bufferOffset);
}
代码示例来源:origin: libgdx/libgdx
@Override
public void run () {
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1);
try {
int c = 0;
while ((c = reader.read()) != -1) {
callback.character((char)c);
}
} catch (IOException e) {
// e.printStackTrace();
}
}
});
代码示例来源:origin: stanfordnlp/CoreNLP
private void readRawBytes(String fileName) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(fileName));
StringBuffer buf = new StringBuffer();
int c;
while ((c = in.read()) >= 0)
buf.append((char) c);
mRawBuffer = buf.toString();
// System.out.println(mRawBuffer);
in.close();
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Gzip file.
*
* @param zipFileName
* @param mDestFile
* @throws Exception
*/
public static void gzips(String zipFileName, String mDestFile) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(zipFileName), "UTF-8"));
BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(mDestFile)));
int c;
while ((c = in.read()) != -1) {
out.write(String.valueOf((char) c).getBytes("UTF-8"));
}
in.close();
out.close();
}
代码示例来源:origin: jamesdbloom/mockserver
public static String readInputStreamToString(Socket socket) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
StringBuilder result = new StringBuilder();
String line;
Integer contentLength = null;
while ((line = bufferedReader.readLine()) != null) {
if (line.startsWith("content-length") || line.startsWith("Content-Length")) {
contentLength = Integer.parseInt(line.split(":")[1].trim());
}
if (line.length() == 0) {
if (contentLength != null) {
result.append(NEW_LINE);
for (int position = 0; position < contentLength; position++) {
result.append((char) bufferedReader.read());
}
}
break;
}
result.append(line).append(NEW_LINE);
}
return result.toString();
}
代码示例来源:origin: marytts/marytts
public static String getReaderAsString(Reader reader) throws IOException {
StringWriter sw = new StringWriter();
BufferedReader in = new BufferedReader(reader);
char[] buf = new char[8192];
int n;
while ((n = in.read(buf)) > 0) {
sw.write(buf, 0, n);
}
return sw.toString();
}
代码示例来源:origin: dcm4che/dcm4che
private static void printNextStepMessage(String message) throws IOException {
System.out.println("===========================================================");
System.out.println(message + ". Press <enter> to continue.");
System.out.println("===========================================================");
bufferedReader.read();
}
代码示例来源:origin: JetBrains/ideavim
@NotNull
private static String readFile(@NotNull File file) throws IOException {
final BufferedReader reader = new BufferedReader(new FileReader(file));
final StringBuilder builder = new StringBuilder();
final char[] buffer = new char[BUFSIZE];
int n;
while ((n = reader.read(buffer)) > 0) {
builder.append(buffer, 0, n);
}
return builder.toString();
}
}
代码示例来源:origin: org.drools/drools-core
public String readInputStreamReaderAsString(InputStreamReader in) throws IOException {
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(in);
char[] buf = new char[1024];
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();
return fileData.toString();
}
}
代码示例来源:origin: sleekbyte/tailor
/**
* Checks whether a file contains any leading whitespace characters.
*
* @param inputFile the file to check for leading whitespace
* @return true if file starts with whitespace
* @throws IOException if the file cannot be read
*/
public static boolean hasLeadingWhitespace(File inputFile) throws IOException {
BufferedReader reader = Files.newBufferedReader(inputFile.toPath());
int character = reader.read();
if (character != -1 && Character.isWhitespace((char) character)) {
return true;
}
reader.close();
return false;
}
}
代码示例来源:origin: ainilili/ratel
/**
* Convert input stream to string
*
* @param inStream Input stream
* @return {@link String}
* @throws IOException If an I/O error occurs
*/
public static String convertToString(InputStream inStream){
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
StringBuilder reqStr = new StringBuilder();
char[] buf = new char[2048];
int len = -1;
try {
while ((len = br.read(buf)) != -1) {
reqStr.append(new String(buf, 0, len));
}
br.close();
}catch(IOException e) {
return null;
}finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return reqStr.toString();
}
代码示例来源:origin: stanfordnlp/CoreNLP
public static void main(String argv[]) throws Exception {
if(argv.length != 1){
log.info("Usage: java edu.stanford.nlp.ie.machinereading.common.RobustTokenizer <file to tokenize>");
System.exit(1);
}
// tokenize this file
BufferedReader is =
new BufferedReader(new FileReader(argv[0]));
// read the whole file in a buffer
// XXX: for sure there are more efficient ways of reading a file...
int ch;
StringBuffer buffer = new StringBuffer();
while((ch = is.read()) != -1) buffer.append((char) ch);
// create the tokenizer object
RobustTokenizer<Word> t = new RobustTokenizer<>(buffer.toString());
List<Word> tokens = t.tokenize();
for (Word token : tokens) {
System.out.println(token);
}
}
}
代码示例来源:origin: org.assertj/assertj-core
private static String loadContents(InputStream stream, Charset charset) throws IOException {
try (StringWriter writer = new StringWriter();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset))) {
int c;
while ((c = reader.read()) != -1) {
writer.write(c);
}
return writer.toString();
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
private HttpCmdRequest parseRequest() throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
int read = in.read(buf);
while (read >= 0 && size > 0 && !postLine.endsWith("\r\n")) {
size -= read;
postLine += String.valueOf(buf, 0, read);
if (size > 0)
read = in.read(buf);
代码示例来源:origin: marytts/marytts
public static String getReaderAsString(Reader reader) throws IOException {
StringWriter sw = new StringWriter();
BufferedReader in = new BufferedReader(reader);
char[] buf = new char[8192];
int n;
while ((n = in.read(buf)) > 0) {
sw.write(buf, 0, n);
}
return sw.toString();
}
代码示例来源:origin: stackoverflow.com
private static String File2String(String fileName) throws
java.io.FileNotFoundException, java.io.IOException
{
File file = new File(fileName);
char[] buffer = null;
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
buffer = new char[(int)file.length()];
int i = 0;
int c = bufferedReader.read();
while (c != -1) {
buffer[i++] = (char)c;
c = bufferedReader.read();
}
return new String(buffer);
}
代码示例来源:origin: geoserver/geoserver
/**
* Constructor with raw request string. Calls parent.
*
* @param reader A reader of the request from the http client.
* @param req The actual request made.
* @throws ServiceException DOCUMENT ME!
* @throws IOException
*/
public void read(BufferedReader requestReader, HttpServletRequest req)
throws ServiceException, IOException {
final StringBuffer output = new StringBuffer();
int c;
while (-1 != (c = requestReader.read())) {
output.append((char) c);
}
requestReader.close();
this.queryString = output.toString();
this.requestParams = KvpRequestReader.parseKvpSet(this.queryString);
}
代码示例来源:origin: kaaproject/kaa
/**
* Read file.
*
* @param file the file
* @return the string
* @throws IOException Signals that an I/O exception has occurred.
*/
static String readFile(File file) throws IOException {
String result = null;
try {
StringBuffer fileData = new StringBuffer();
FileInputStream input = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
char[] buf = new char[1024];
int numRead = 0;
while ((numRead = reader.read(buf)) != -1) {
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
result = fileData.toString();
} catch (IOException ex) {
LOG.error("Unable to read from specified file '"
+ file + "'! Error: " + ex.getMessage(), ex);
throw ex;
}
return result;
}
代码示例来源:origin: cSploit/android
BufferedReader reader = new BufferedReader(new FileReader(fileName));
char[] buf = new char[1024];
int read = 0;
String js = "";
while((read = reader.read(buf)) != -1){
buffer.append(String.valueOf(buf, 0, read));
reader.close();
代码示例来源:origin: joel-costigliola/assertj-core
private static String loadContents(InputStream stream, Charset charset) throws IOException {
try (StringWriter writer = new StringWriter();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset))) {
int c;
while ((c = reader.read()) != -1) {
writer.write(c);
}
return writer.toString();
}
}
内容来源于网络,如有侵权,请联系作者删除!