List of usage examples for java.io BufferedReader read
public int read(char cbuf[], int off, int len) throws IOException
From source file:hudson.Util.java
public static String loadFile(File logfile, Charset charset) throws IOException { if (!logfile.exists()) return ""; StringBuilder str = new StringBuilder((int) logfile.length()); BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(logfile), charset)); char[] buf = new char[1024]; int len;/*from w w w . jav a2s . c o m*/ while ((len = r.read(buf, 0, buf.length)) > 0) str.append(buf, 0, len); r.close(); return str.toString(); }
From source file:com.vmware.aurora.vc.VcFileManager.java
static private String loadOvfContents(String ovfPath) throws IOException { BufferedReader reader = null; char[] ovfBuf = null; try {//from w w w . jav a2s.co m File ovfFile = new File(ovfPath); reader = new BufferedReader(new FileReader(ovfFile)); AuAssert.check(ovfFile.length() < MAX_OVF_SIZE); int totalLen = (int) (ovfFile.length() < MAX_OVF_SIZE ? ovfFile.length() : MAX_OVF_SIZE); ovfBuf = new char[totalLen]; int len, offset = 0; while (offset < totalLen && (len = reader.read(ovfBuf, offset, totalLen - offset)) != -1) { offset += len; } } finally { if (reader != null) { reader.close(); } } return new String(ovfBuf); }
From source file:org.eredlab.g4.ccl.net.DaytimeTCPClient.java
/*** * Retrieves the time string from the server and returns it. The * server will have closed the connection at this point, so you should * call// w ww . ja v a2 s. c om * {@link org.apache.commons.net.SocketClient#disconnect disconnect } * after calling this method. To retrieve another time, you must * initiate another connection with * {@link org.apache.commons.net.SocketClient#connect connect } * before calling <code> getTime() </code> again. * <p> * @return The time string retrieved from the server. * @exception IOException If an error occurs while fetching the time string. ***/ public String getTime() throws IOException { int read; StringBuffer result = new StringBuffer(__buffer.length); BufferedReader reader; reader = new BufferedReader(new InputStreamReader(_input_)); while (true) { read = reader.read(__buffer, 0, __buffer.length); if (read <= 0) break; result.append(__buffer, 0, read); } return result.toString(); }
From source file:Ch5Persistent.java
private void readContent(BufferedReader reader, int contentLength) throws IOException { char[] buffer = new char[contentLength]; reader.read(buffer, 0, contentLength); styledText.append(new String(buffer)); }
From source file:com.simplenoteapp.test.Test.java
private String readResponse(InputStream is) throws IOException { char cbuf[] = new char[BUFFER_SIZE]; StringBuffer sbuf = new StringBuffer(); BufferedReader r = null; try {/*from w ww . jav a 2 s . c om*/ r = new BufferedReader(new InputStreamReader(is)); for (;;) { int n = r.read(cbuf, 0, BUFFER_SIZE); if (n == -1) break; sbuf.append(cbuf, 0, n); } } finally { try { r.close(); } catch (IOException e) { } } return sbuf.toString(); }
From source file:org.apache.zeppelin.shell.terminal.service.TerminalService.java
private void printReader(BufferedReader bufferedReader) { try {/* w w w . j a v a2s.c o m*/ int nRead; char[] data = new char[10 * 1024]; while ((nRead = bufferedReader.read(data, 0, data.length)) != -1) { StringBuilder builder = new StringBuilder(nRead); builder.append(data, 0, nRead); print(builder.toString()); } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }
From source file:mondrian.spi.impl.FilterDynamicSchemaProcessor.java
/** * Reads the contents of a schema as a stream and returns the result as a * string./*w w w. j a v a2 s.c om*/ * * <p> * The default implementation returns the contents of the schema unchanged. * * @param schemaUrl * the URL of the catalog * @param connectInfo * Connection properties * @param stream * Schema contents represented as a stream * @return the modified schema * @throws Exception * if an error occurs */ protected String filter(String schemaUrl, Util.PropertyList connectInfo, InputStream stream) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(stream)); try { StringBuilder builder = new StringBuilder(); char[] buf = new char[2048]; int readCount; while ((readCount = in.read(buf, 0, buf.length)) >= 0) { builder.append(buf, 0, readCount); } return builder.toString(); } finally { in.close(); } }
From source file:org.apache.hadoop.util.SSHRemoteExecution.java
protected void parseExecResult(BufferedReader lines) throws IOException { output = new StringBuffer(); char[] buf = new char[512]; int nRead;//w w w. ja v a 2 s . c om while ((nRead = lines.read(buf, 0, buf.length)) > 0) { output.append(buf, 0, nRead); } }
From source file:com.pursuer.reader.easyrss.network.AbsDataSyncer.java
protected String parseContent(final Reader in) throws DataSyncerException { final StringBuilder builder = new StringBuilder(); try {//from w w w .j av a2 s .c o m final char buff[] = new char[8192]; int len; final BufferedReader reader = new BufferedReader(in, 8192); while ((len = reader.read(buff, 0, buff.length)) != -1) { builder.append(buff, 0, len); } return builder.toString(); } catch (IOException e) { throw new DataSyncerException(e); } finally { try { in.close(); } catch (final IOException exception) { exception.printStackTrace(); } } }
From source file:com.ibm.liberty.starter.ProjectZipConstructor.java
public byte[] getHtmlFile() throws IOException { InputStream htmlIS = this.getClass().getClassLoader().getResourceAsStream(BASE_INDEX_HTML); HashMap<String, byte[]> techDescriptions = new HashMap<String, byte[]>(); for (Service service : services.getServices()) { Provider provider = serviceConnector.getProvider(service); String description = provider.getDescription(); byte[] bytes = description.getBytes(); techDescriptions.put(service.getId(), bytes); }/*from ww w . j a va 2s .c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); final int MAX_SIZE = 200000; char[] buffer = new char[MAX_SIZE]; BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(htmlIS)); reader.read(buffer, 0, MAX_SIZE); } catch (Exception e) { return null; } finally { reader.close(); } String contents = new String(buffer); int index = contents.indexOf("<div id=\"technologies\">"); if (index != -1) { int length = contents.length(); String first = contents.substring(0, index); String last = contents.substring(index, length); baos.write(first.getBytes()); Set<String> keys = techDescriptions.keySet(); for (String key : keys) { baos.write(techDescriptions.get(key)); } baos.write(last.getBytes()); } return baos.toByteArray(); }