当前位置: 首页>>代码示例>>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;未经允许,请勿转载。