当前位置: 首页>>代码示例>>Java>>正文


Java Reader.read方法代码示例

本文整理汇总了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();
}
 
开发者ID:sing1ee,项目名称:elasticsearch-jieba-plugin,代码行数:18,代码来源:JiebaAdapter.java

示例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();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FileEncodingQueryTest.java

示例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();
        }
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:19,代码来源:HttpUtils.java

示例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);
        }
    };
}
 
开发者ID:PawelAdamski,项目名称:HttpClientMock,代码行数:27,代码来源:HttpResponseMatchers.java

示例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();
    }
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:22,代码来源:IOUtils.java

示例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();
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:13,代码来源:TreeView.java

示例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");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:AbstractCharArrayType.java

示例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();
    }
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:17,代码来源:Streams.java

示例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;
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:21,代码来源:CopyUtils.java

示例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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:Streams.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:DefaultDiff.java

示例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);
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:14,代码来源:Engine.java

示例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();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:MLetParser.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Transfer.java

示例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;
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:22,代码来源:IOUtils.java


注:本文中的java.io.Reader.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。