List of usage examples for java.io Reader read
public int read() throws IOException
From source file:de.quist.samy.remocon.RemoteSession.java
private String readRegistrationReply(Reader reader) throws IOException { logger.debug("Reading registration reply"); reader.read(); // Unknown byte 0x02 String text1 = readText(reader); // Read "unknown.livingroom.iapp.samsung" for new RC and "iapp.samsung" for already registered RC logger.debug("Received ID: " + text1); char[] result = readCharArray(reader); // Read result sequence if (Arrays.equals(result, ALLOWED_BYTES)) { logger.debug("Registration successfull"); return ALLOWED; } else if (Arrays.equals(result, DENIED_BYTES)) { logger.warn("Registration denied"); return DENIED; } else if (Arrays.equals(result, TIMEOUT_BYTES)) { logger.warn("Registration timed out"); return TIMEOUT; } else {/*from w ww. j a v a 2 s .c o m*/ StringBuilder sb = new StringBuilder(); for (char c : result) { sb.append(Integer.toHexString(c)); sb.append(' '); } String hexReturn = sb.toString(); { logger.error("Received unknown registration reply: " + hexReturn); } return hexReturn; } }
From source file:com.npower.cp.xmlinventory.OTATemplateItem.java
/** * Set the content by filename.//w w w. j a va 2 s . co m * The method will be called in Common Digester * @param filename * @throws IOException */ public void setFilename(String filename) throws IOException { if (StringUtils.isEmpty(filename)) { return; } String baseDir = System.getProperty(OTAInventoryImpl.CP_TEMPLATE_RESOURCE_DIR); File file = new File(baseDir, filename); Reader reader = new FileReader(file); StringWriter writer = new StringWriter(); int c = reader.read(); while (c > 0) { writer.write(c); c = reader.read(); } this.content = writer.toString(); reader.close(); }
From source file:net.metanotion.json.StreamingParser.java
private int skipWhitespace(final Reader in) throws IOException { int c;//w ww .jav a 2 s . c o m do { c = in.read(); } while (Character.isWhitespace((char) c)); return c; }
From source file:com.yahoo.platform.yuitest.coverage.results.SummaryCoverageReport.java
/** * Creates a new report object from a reader. * @param in The reader containing JSON information. * @throws java.io.IOException//from ww w . j a va 2 s . c om * @throws org.json.JSONException */ public SummaryCoverageReport(Reader in) throws IOException, JSONException { StringBuilder builder = new StringBuilder(); int c; while ((c = in.read()) != -1) { builder.append((char) c); } this.data = new JSONObject(builder.toString()); this.directories = new HashMap<String, DirectoryCoverageReport>(); generateFileReports(); }
From source file:net.metanotion.json.StreamingParser.java
private String lexExp(final Reader in) throws IOException { in.mark(MAX_BUFFER);// w w w . j a va 2 s. c o m int c = in.read(); if (Character.toLowerCase(c) == 'e') { c = in.read(); if (c == '+') { return "e+" + lexDigits(in); } else if (c == '-') { return "e-" + lexDigits(in); } else if (Character.isDigit(c)) { return (new String(Character.toChars(c))) + lexDigits(in); } else if (c == -1) { throw new ParserException("Unexpected end of stream"); } else { throw new ParserException( "Expected exponent, instead found: '" + (new String(Character.toChars(c))) + QUOTE); } } else { in.reset(); return ""; } }
From source file:io.vertx.ext.shell.term.TelnetTermServerTest.java
@Test public void testWrite(TestContext context) throws IOException { startTelnet(context, term -> {//from ww w .j av a 2 s .c o m term.write("hello_from_server"); }); client.connect("localhost", server.actualPort()); Reader reader = new InputStreamReader(client.getInputStream()); StringBuilder sb = new StringBuilder("hello_from_server"); while (sb.length() > 0) { int c = reader.read(); context.assertNotEquals(-1, c); context.assertEquals(c, (int) sb.charAt(0)); sb.deleteCharAt(0); } }
From source file:fedroot.dacs.swingdemo.DacsSwingDemo.java
/** * Loads contents of the input stream in a separate thread. * @param is input stream to be rendered as HTML */// w w w .ja v a 2s . com private void loadPage(final String contenttype, final String url) { // create a new thread to load the URL from final StringBuffer stringBuffer = new StringBuffer(); new Thread() { @Override public void run() { { InputStream inputStream = null; try { inputStream = sessionManager.getInputStream(url); Reader reader = new InputStreamReader(new BufferedInputStream(inputStream)); int character; while ((character = reader.read()) != -1) { stringBuffer.append((char) character); } inputStream.close(); if (inputStream != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { setDocumentContent(contenttype, stringBuffer.toString()); } }); } } catch (DacsException ex) { // note: we EXPECT DacsExceptions logger.log(Level.FINEST, ex.getMessage()); } catch (IOException ex) { logger.log(Level.SEVERE, ex.getMessage()); } finally { setDocumentContent(contenttype, stringBuffer.toString()); try { if (inputStream != null) { inputStream.close(); } } catch (IOException ex) { Logger.getLogger(DacsSwingDemo.class.getName()).log(Level.SEVERE, null, ex); } } } } }.start(); }
From source file:com.legstar.test.cixs.AbstractHttpClientTester.java
/** * The HttpClient getResponseBodyAsString returns a systematic warning when * the response has no content-length.//from www .j av a 2 s. c o m * * @param is the http response as a stream * @param charset the response character set * @return the result string */ protected String getResponseBodyAsString(final InputStream is, final String charset) { try { Reader reader = new BufferedReader(new InputStreamReader(is, charset)); StringBuilder sb = new StringBuilder(); int ch; while ((ch = reader.read()) > -1) { sb.append((char) ch); } is.close(); return sb.toString(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:fr.paris.lutece.portal.service.search.PageIndexer.java
/** * Builds a document which will be used by Lucene during the indexing of the * pages of the site with the following/* ww w . j a va 2 s . c o m*/ * fields : summary, uid, url, contents, title and description. * @return the built Document * @param strUrl The base URL for documents * @param page the page to index * @throws IOException The IO Exception * @throws InterruptedException The InterruptedException * @throws SiteMessageException occurs when a site message need to be * displayed */ protected Document getDocument(Page page, String strUrl) throws IOException, InterruptedException, SiteMessageException { // make a new, empty document Document doc = new Document(); // Add the url as a field named "url". Use an UnIndexed field, so // that the url is just stored with the document, but is not searchable. doc.add(new Field(SearchItem.FIELD_URL, strUrl, Field.Store.YES, Field.Index.NOT_ANALYZED)); // Add the last modified date of the file a field named "modified". // Use a field that is indexed (i.e. searchable), but don't tokenize // the field into words. String strDate = DateTools.dateToString(page.getDateUpdate(), DateTools.Resolution.DAY); doc.add(new Field(SearchItem.FIELD_DATE, strDate, Field.Store.YES, Field.Index.NOT_ANALYZED)); // Add the uid as a field, so that index can be incrementally maintained. // This field is not stored with document, it is indexed, but it is not // tokenized prior to indexing. String strIdPage = String.valueOf(page.getId()); doc.add(new Field(SearchItem.FIELD_UID, strIdPage, Field.Store.NO, Field.Index.NOT_ANALYZED)); String strPageContent = _pageService.getPageContent(page.getId(), 0, null); StringReader readerPage = new StringReader(strPageContent); HTMLParser parser = new HTMLParser(readerPage); //the content of the article is recovered in the parser because this one //had replaced the encoded caracters (as é) by the corresponding special caracter (as ?) Reader reader = parser.getReader(); int c; StringBuilder sb = new StringBuilder(); while ((c = reader.read()) != -1) { sb.append(String.valueOf((char) c)); } reader.close(); // Add the tag-stripped contents as a Reader-valued Text field so it will // get tokenized and indexed. StringBuilder sbFieldContent = new StringBuilder(); StringBuilder sbFieldMetadata = new StringBuilder(); sbFieldContent.append(page.getName()).append(" ").append(sb.toString()); // Add the metadata description of the page if it exists if (page.getDescription() != null) { sbFieldContent.append(" ").append(page.getDescription()); } // Add the metadata keywords of the page if it exists String strMetaKeywords = page.getMetaKeywords(); if (StringUtils.isNotBlank(strMetaKeywords)) { sbFieldContent.append(" ").append(strMetaKeywords); sbFieldMetadata.append(strMetaKeywords); } doc.add(new Field(SearchItem.FIELD_CONTENTS, sbFieldContent.toString(), Field.Store.NO, Field.Index.ANALYZED)); if (StringUtils.isNotBlank(page.getMetaDescription())) { if (sbFieldMetadata.length() > 0) { sbFieldMetadata.append(" "); } sbFieldMetadata.append(page.getMetaDescription()); } if (sbFieldMetadata.length() > 0) { doc.add(new Field(SearchItem.FIELD_METADATA, sbFieldMetadata.toString(), Field.Store.NO, Field.Index.ANALYZED)); } // Add the title as a separate Text field, so that it can be searched // separately. doc.add(new Field(SearchItem.FIELD_TITLE, page.getName(), Field.Store.YES, Field.Index.NO)); if ((page.getDescription() != null) && (page.getDescription().length() > 1)) { // Add the summary as an UnIndexed field, so that it is stored and returned // with hit documents for display. doc.add(new Field(SearchItem.FIELD_SUMMARY, page.getDescription(), Field.Store.YES, Field.Index.ANALYZED)); } doc.add(new Field(SearchItem.FIELD_TYPE, INDEX_TYPE_PAGE, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field(SearchItem.FIELD_ROLE, page.getRole(), Field.Store.YES, Field.Index.NOT_ANALYZED)); // return the document return doc; }
From source file:com.stimulus.archiva.incoming.SMTPFilterReader.java
public SMTPFilterReader(Reader isr, long maxsize) throws IOException, SMTPEndStreamException { super(isr);/*from w w w.j a v a 2 s .com*/ logger.debug("smtpinputstream() construct"); this.isr = isr; size = 5; this.maxsize = maxsize * 1024 * 1024; push(13); push(10); for (int i = 0; i < 4; i++) { push(isr.read()); if (CRLFDotCRLF()) throw new SMTPEndStreamException("end of stream", logger, ChainedException.Level.DEBUG); transparent(); } logger.debug("smtpinputstream() constructor end"); }