本文整理匯總了Java中java.io.Reader類的典型用法代碼示例。如果您正苦於以下問題:Java Reader類的具體用法?Java Reader怎麽用?Java Reader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Reader類屬於java.io包,在下文中一共展示了Reader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: composeAll
import java.io.Reader; //導入依賴的package包/類
/**
* Parse all YAML documents in a stream and produce corresponding
* representation trees.
*
* @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
* @param yaml
* stream of YAML documents
* @return parsed root Nodes for all the specified YAML documents
*/
public Iterable<Node> composeAll(Reader yaml) {
final Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
constructor.setComposer(composer);
Iterator<Node> result = new Iterator<Node>() {
public boolean hasNext() {
return composer.checkNode();
}
public Node next() {
return composer.getNode();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new NodeIterable(result);
}
示例2: setNCharacterStream
import java.io.Reader; //導入依賴的package包/類
/**
* @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader, long)
*/
public void setNCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
// can't take if characterEncoding isn't utf8
if (!this.charEncoding.equalsIgnoreCase("UTF-8") && !this.charEncoding.equalsIgnoreCase("utf8")) {
throw SQLError.createSQLException("Can not call setNCharacterStream() when connection character set isn't UTF-8", getExceptionInterceptor());
}
checkClosed();
if (reader == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, true);
resetToType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = reader;
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = length;
} else {
binding.bindLength = -1;
}
}
}
示例3: testBuildIOException
import java.io.Reader; //導入依賴的package包/類
@Test
public void testBuildIOException() {
new MockUp<Properties>() {
@Mock
public synchronized void load(Reader reader) throws IOException {
throw new IOException();
}
};
boolean validAssert = true;
try {
SSLOption option = SSLOption.build(DIR + "/server.ssl.properties");
Assert.assertEquals("revoke.crl", option.getCrl());
} catch (Exception e) {
Assert.assertEquals("java.lang.IllegalArgumentException", e.getClass().getName());
validAssert = false;
}
Assert.assertFalse(validAssert);
}
示例4: copy
import java.io.Reader; //導入依賴的package包/類
/**
* Copy from reader to writer
*
* @param input
* @param output
* @return this request
* @throws IOException
*/
protected HttpRequest copy(final Reader input, final Writer output)
throws IOException {
return new CloseOperation<HttpRequest>(input, ignoreCloseExceptions) {
@Override
public HttpRequest run() throws IOException {
final char[] buffer = new char[bufferSize];
int read;
while ((read = input.read(buffer)) != -1) {
output.write(buffer, 0, read);
totalWritten += read;
progress.onUpload(totalWritten, -1);
}
return HttpRequest.this;
}
}.call();
}
示例5: read
import java.io.Reader; //導入依賴的package包/類
/**
* Reads from the provided reader until the end and returns a CsvContainer containing the data.
*
* This library uses built-in buffering, so you do not need to pass in a buffered Reader
* implementation such as {@link java.io.BufferedReader}.
* Performance may be even likely better if you do not.
*
* @param reader the data source to read from.
* @return the entire file's data - never {@code null}.
* @throws IOException if an I/O error occurs.
*/
public CsvContainer read(final Reader reader) throws IOException {
final CsvParser csvParser =
parse(Objects.requireNonNull(reader, "reader must not be null"));
final List<CsvRow> rows = new ArrayList<>();
CsvRow csvRow;
while ((csvRow = csvParser.nextRow()) != null) {
rows.add(csvRow);
}
if (rows.isEmpty()) {
return null;
}
final List<String> header = containsHeader ? csvParser.getHeader() : null;
return new CsvContainer(header, rows);
}
示例6: test_scanInt
import java.io.Reader; //導入依賴的package包/類
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 1024; ++i) {
if (i != 0) {
buf.append(',');
}
buf.append(i);
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
JSONArray array = (JSONArray) parser.parse();
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals(i, ((Integer) array.get(i)).intValue());
}
}
示例7: extractCommands
import java.io.Reader; //導入依賴的package包/類
@Override
public String[] extractCommands(Reader reader) {
BufferedReader bufferedReader = new BufferedReader( reader );
List<String> statementList = new LinkedList<String>();
try {
for ( String sql = bufferedReader.readLine(); sql != null; sql = bufferedReader.readLine() ) {
String trimmedSql = sql.trim();
if ( StringHelper.isEmpty( trimmedSql ) || isComment( trimmedSql ) ) {
continue;
}
if ( trimmedSql.endsWith( ";" ) ) {
trimmedSql = trimmedSql.substring( 0, trimmedSql.length() - 1 );
}
statementList.add( trimmedSql );
}
return statementList.toArray( new String[statementList.size()] );
}
catch ( IOException e ) {
throw new ImportScriptException( "Error during import script parsing.", e );
}
}
示例8: shouldNotFailIfDeleteHasBody
import java.io.Reader; //導入依賴的package包/類
@Test
public void shouldNotFailIfDeleteHasBody() throws Exception {
getRequest("DELETE", getUrl("/user/123"))
.setParameter("some", "parameter")
.execute();
verify(converter).serialize(mapCaptor.capture());
verify(converter).parse(any(Class.class), any(Reader.class));
verifyNoMoreInteractions(converter);
Map<String, Object> body = mapCaptor.getValue();
assertThat(body, hasEntry("some", (Object) "parameter"));
verify(client).newCall(requestCaptor.capture());
okhttp3.Request request = requestCaptor.getValue();
assertThat(request.method(), is(equalTo("DELETE")));
assertThat(request.url().encodedPath(), is(equalTo("/user/123")));
}
示例9: getUTF8Reader
import java.io.Reader; //導入依賴的package包/類
/**
* Returns a Reader for reading the UTF-8 encoded file at the specified
* path.
*/
static public Reader getUTF8Reader(String path)
throws FileNotFoundException
{
FileInputStream in = new FileInputStream(path);
InputStreamReader reader = null;
try
{
reader = new InputStreamReader(in, _UTF8_ENCODING);
}
catch (UnsupportedEncodingException e)
{
// UTF-8 should always be supported!
assert false;
return null;
}
return new BufferedReader(reader);
}
示例10: initReader
import java.io.Reader; //導入依賴的package包/類
@Override
protected Reader initReader(String fieldName, Reader reader) {
if (charFilters != null && charFilters.length > 0) {
for (CharFilterFactory charFilter : charFilters) {
reader = charFilter.create(reader);
}
}
return reader;
}
示例11: getNonNullScriptReader
import java.io.Reader; //導入依賴的package包/類
@NonNull
public Reader getNonNullScriptReader() {
Reader reader = getScriptReader();
if (reader == null) {
return new StringReader(getScript());
}
return reader;
}
示例12: getCharacterStream
import java.io.Reader; //導入依賴的package包/類
@Override
public Reader getCharacterStream(int columnIndex) throws SQLException {
checkColumnBounds(columnIndex);
try {
String value = table.getString(columnIndex - 1);
if (!wasNull())
return new StringReader(value);
return null;
} catch (Exception x) {
throw SQLError.get(x);
}
}
示例13: getImmunizationById
import java.io.Reader; //導入依賴的package包/類
@Read
public Immunization getImmunizationById(HttpServletRequest httpRequest, @IdParam IdType internalId) {
ProducerTemplate template = context.createProducerTemplate();
Immunization immunization = null;
IBaseResource resource = null;
try {
InputStream inputStream = (InputStream) template.sendBody("direct:FHIRImmunization",
ExchangePattern.InOut,httpRequest);
Reader reader = new InputStreamReader(inputStream);
resource = ctx.newJsonParser().parseResource(reader);
} catch(Exception ex) {
log.error("JSON Parse failed " + ex.getMessage());
throw new InternalErrorException(ex.getMessage());
}
if (resource instanceof Immunization) {
immunization = (Immunization) resource;
}else if (resource instanceof OperationOutcome)
{
OperationOutcome operationOutcome = (OperationOutcome) resource;
log.info("Sever Returned: "+ctx.newJsonParser().encodeResourceToString(operationOutcome));
OperationOutcomeFactory.convertToException(operationOutcome);
} else {
throw new InternalErrorException("Unknown Error");
}
return immunization;
}
開發者ID:nhsconnect,項目名稱:careconnect-reference-implementation,代碼行數:36,代碼來源:ImmunizationResourceProvider.java
示例14: 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();
}
}
示例15: setContent
import java.io.Reader; //導入依賴的package包/類
/** Sets the javadoc content as HTML document */
public void setContent(final String content, final String reference) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
Reader in = new StringReader("<HTML><BODY>"+content+"</BODY></HTML>");//NOI18N
try{
Document doc = getDocument();
doc.remove(0, doc.getLength());
getEditorKit().read(in, getDocument(), 0); //!!! still too expensive to be called from AWT
setCaretPosition(0);
if (reference != null) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
scrollToReference(reference);
}
});
} else {
scrollRectToVisible(new Rectangle(0,0,0,0));
}
}catch(IOException ioe){
ioe.printStackTrace();
}catch(BadLocationException ble){
ble.printStackTrace();
}
}
});
}