當前位置: 首頁>>代碼示例>>Java>>正文


Java Reader類代碼示例

本文整理匯總了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);
}
 
開發者ID:imkiva,項目名稱:AndroidApktool,代碼行數:28,代碼來源:Yaml.java

示例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;
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:28,代碼來源:JDBC4ServerPreparedStatement.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:19,代碼來源:SSLOptionTest.java

示例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();
}
 
開發者ID:auv1107,項目名稱:TextEmoji,代碼行數:26,代碼來源:HttpRequest.java

示例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);
}
 
開發者ID:mun3team,項目名稱:mun3code,代碼行數:29,代碼來源:CsvReader.java

示例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()); 
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:JSONReaderScannerTest_int.java

示例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 );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:SingleLineSqlCommandExtractor.java

示例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")));
}
 
開發者ID:auth0,項目名稱:Guardian.java,代碼行數:19,代碼來源:RequestTest.java

示例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);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:24,代碼來源:FileUtils.java

示例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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:CustomAnalyzer.java

示例11: getNonNullScriptReader

import java.io.Reader; //導入依賴的package包/類
@NonNull
public Reader getNonNullScriptReader() {
    Reader reader = getScriptReader();
    if (reader == null) {
        return new StringReader(getScript());
    }
    return reader;
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:9,代碼來源:JavaScriptSource.java

示例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);
    }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:13,代碼來源:JDBC4ResultSet.java

示例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();
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:15,代碼來源:Util.java

示例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();
            }
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:HTMLDocView.java


注:本文中的java.io.Reader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。