本文整理汇总了Java中java.io.Reader.read方法的典型用法代码示例。如果您正苦于以下问题:Java Reader.read方法的具体用法?Java Reader.read怎么用?Java Reader.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.Reader
的用法示例。
在下文中一共展示了Reader.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reset
import java.io.Reader; //导入方法依赖的package包/类
public synchronized void reset(Reader input) {
try {
StringBuilder bdr = new StringBuilder();
char[] buf = new char[1024];
int size = 0;
while ((size = input.read(buf, 0, buf.length)) != -1) {
String tempstr = new String(buf, 0, size);
bdr.append(tempstr);
}
raw = bdr.toString().trim();
} catch (IOException e) {
e.printStackTrace();
}
List<SegToken> list = jiebaTagger.process(raw, segMode);
tokens = list.iterator();
}
示例2: copyFile
import java.io.Reader; //导入方法依赖的package包/类
private void copyFile (FileObject from, FileObject to) throws IOException {
Charset ci = FileEncodingQuery.getEncoding(from);
Reader in = new BufferedReader (new InputStreamReader (from.getInputStream(),ci));
try {
FileLock lck = to.lock();
try {
Charset co = FileEncodingQuery.getEncoding(to);
Writer out = new BufferedWriter (new OutputStreamWriter (to.getOutputStream(lck),co));
try {
char[] data = new char[1024];
int len;
while ((len=in.read(data, 0, data.length))>0) {
out.write(data, 0, len);
}
} finally {
out.close();
}
} finally {
lck.releaseLock();
}
} finally {
in.close();
}
}
示例3: getStreamAsString
import java.io.Reader; //导入方法依赖的package包/类
private static String getStreamAsString(InputStream stream, String charset) throws IOException {
try {
Reader reader = new InputStreamReader(stream, charset);
StringBuilder response = new StringBuilder();
final char[] buff = new char[1024];
int read = 0;
while ((read = reader.read(buff)) > 0) {
response.append(buff, 0, read);
}
return response.toString();
} finally {
if (stream != null) {
stream.close();
}
}
}
示例4: hasContent
import java.io.Reader; //导入方法依赖的package包/类
public static Matcher<? super HttpResponse> hasContent(final String content, final String charset) {
return new BaseMatcher<HttpResponse>() {
public boolean matches(Object o) {
try {
HttpResponse response = (HttpResponse) o;
Reader reader = new InputStreamReader(response.getEntity().getContent(), charset);
int intValueOfChar;
String targetString = "";
while ((intValueOfChar = reader.read()) != -1) {
targetString += (char) intValueOfChar;
}
reader.close();
return targetString.equals(content);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public void describeTo(Description description) {
description.appendText(content);
}
};
}
示例5: toString0
import java.io.Reader; //导入方法依赖的package包/类
private static String toString0(Reader reader, int maxLength) throws IOException {
if (maxLength < 0) {
throw new IllegalArgumentException("Invalid length: " + maxLength);
} else if (maxLength == 0) {
return "";
} else {
int size = Math.min(maxLength, BUFFER_SIZE);
StringBuilder str = new StringBuilder();
char[] buf = new char[size];
int len;
while ((len = reader.read(buf)) != -1) {
if (str.length() + len < maxLength) {
str.append(buf, 0, len);
} else {
str.append(buf, 0, maxLength - str.length());
break;
}
}
return str.toString();
}
}
示例6: convertToString
import java.io.Reader; //导入方法依赖的package包/类
private String convertToString(InputStream is) throws IOException {
final char[] buffer = new char[0x10000];
StringBuilder out = new StringBuilder();
Reader in = new InputStreamReader(is, "UTF-8");
int read;
while ((read = in.read(buffer, 0, buffer.length)) >= 0) {
if (read > 0) {
out.append(buffer, 0, read);
}
}
return out.toString();
}
示例7: get
import java.io.Reader; //导入方法依赖的package包/类
public Object get(ResultSet rs, String name) throws SQLException {
Reader stream = rs.getCharacterStream(name);
if ( stream == null ) return toExternalFormat( null );
CharArrayWriter writer = new CharArrayWriter();
for(;;) {
try {
int c = stream.read();
if ( c == -1) return toExternalFormat( writer.toCharArray() );
writer.write( c );
}
catch (IOException e) {
throw new HibernateException("Unable to read character stream from rs");
}
}
}
示例8: readFully
import java.io.Reader; //导入方法依赖的package包/类
/**
* Returns the remainder of 'reader' as a string, closing it when done.
*/
public static String readFully(Reader reader) throws IOException {
try {
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
return writer.toString();
} finally {
reader.close();
}
}
示例9: copy
import java.io.Reader; //导入方法依赖的package包/类
/**
* Copy chars from a <code>Reader</code> to a <code>Writer</code>.
* @param input the <code>Reader</code> to read from
* @param output the <code>Writer</code> to write to
* @return the number of characters copied
* @throws IOException In case of an I/O problem
*/
public static int copy(
Reader input,
Writer output)
throws IOException {
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
int count = 0;
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
示例10: readFully
import java.io.Reader; //导入方法依赖的package包/类
public static int readFully(Reader reader, char[] dest, int offset, int len) throws IOException {
int read = 0;
while (read < len) {
final int r = reader.read(dest, offset + read, len - read);
if (r == -1) {
break;
}
read += r;
}
return read;
}
示例11: cpStream
import java.io.Reader; //导入方法依赖的package包/类
private static void cpStream(Reader in, Writer out) throws IOException {
char[] buff = new char[1024];
int n;
while ((n = in.read(buff)) > 0) {
out.write(buff, 0, n);
}
in.close();
out.close();
}
示例12: eval
import java.io.Reader; //导入方法依赖的package包/类
@Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
StringBuilder sb = new StringBuilder();
try {
int i;
while((i = reader.read()) != -1) {
sb.append((char)i);
}
} catch(IOException e) {
throw new ScriptException(e);
}
return eval(sb.toString(), context);
}
示例13: scanIdentifier
import java.io.Reader; //导入方法依赖的package包/类
/**
* Scan identifier
*/
public String scanIdentifier(Reader in) throws IOException {
StringBuilder buf = new StringBuilder();
while (true) {
if (((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')) ||
((c >= '0') && (c <= '9')) || (c == '_')) {
buf.append((char)c);
c = in.read();
} else {
return buf.toString();
}
}
}
示例14: checkFileData
import java.io.Reader; //导入方法依赖的package包/类
static void checkFileData(File file, String expected) throws Exception {
FileInputStream fis = new FileInputStream(file);
Reader r = new BufferedReader(new InputStreamReader(fis, "ASCII"));
StringBuilder sb = new StringBuilder();
int c;
while ((c = r.read()) != -1)
sb.append((char)c);
String contents = sb.toString();
if (! contents.equals(expected))
throw new Exception("expected: " + expected
+ ", got: " + contents);
r.close();
}
示例15: write
import java.io.Reader; //导入方法依赖的package包/类
/**
* write.
*
* @param reader Reader.
* @param writer Writer.
* @param bufferSize buffer size.
* @return count.
* @throws IOException
*/
public static long write(Reader reader, Writer writer, int bufferSize) throws IOException
{
int read;
long total = 0;
char[] buf = new char[BUFFER_SIZE];
while( ( read = reader.read(buf) ) != -1 )
{
writer.write(buf, 0, read);
total += read;
}
return total;
}