當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。