List of usage examples for java.io Reader read
public int read() throws IOException
From source file:com.rovemonteux.tormessenger.network.NetworkClient.java
public String read() throws IOException { Reader r = new InputStreamReader(netSocket.getInputStream(), Charset.forName("UTF-8")); int intch;//from w ww. j av a 2 s .c o m StringBuilder input = new StringBuilder(); while ((intch = r.read()) != 10) { char ch = (char) intch; input.append(ch); } r.close(); /*if (!(this.remoteUser == null) && !(this.remoteUser.length() < 1)) { chatFrame.chatArea.append(input.toString().trim()+"\n"); }*/ return input.toString().trim(); }
From source file:com.moss.posixfifosockets.PosixFifoSocketServer.java
private void eatTokens(Reader r) throws IOException { for (int c = r.read(); c != END_TOKEN; c = r.read()) { System.out.println("Eating " + (char) c); if (c == BEGIN_TOKEN) { eatTokens(r);//from www . ja v a2s. co m } } }
From source file:com.smile.pentaho.birtplugin.BIRTContentGenerator.java
public void createContent() throws Exception { this.session = PentahoSessionHolder.getSession(); this.repository = PentahoSystem.get(IUnifiedRepository.class, session); RepositoryFile BIRTfile = (RepositoryFile) parameterProviders.get("path").getParameter("file"); String ExecBIRTFilePath = "../../pentaho-solutions/" + BIRTfile.getId() + ".rptdesign"; /*/*from w w w . j a va2 s .c o m*/ * Get BIRT report design from repository */ File ExecBIRTFile = new File(ExecBIRTFilePath); if (!ExecBIRTFile.exists()) { Writer writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(ExecBIRTFilePath), "UTF-8")); try { SimpleRepositoryFileData data = repository.getDataForRead(BIRTfile.getId(), SimpleRepositoryFileData.class); Reader reader = new InputStreamReader(data.getInputStream(), "UTF8"); int c; while ((c = reader.read()) != -1) { writer.write(c); } } catch (Exception e) { Logger.error(getClass().getName(), e.getMessage()); } finally { writer.close(); } } /* * Redirect to BIRT Viewer */ try { //Get informations about user context IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class); String roles = ""; ListIterator li = service.getRolesForUser(null, session.getName()).listIterator(); while (li.hasNext()) { roles = roles + li.next().toString() + ","; } //Redirect HttpServletResponse response = (HttpServletResponse) this.parameterProviders.get("path") .getParameter("httpresponse"); response.sendRedirect("/WebViewerExample/frameset?__report=" + BIRTfile.getId() + ".rptdesign&__showtitle=false&username=" + session.getName() + "&userroles=" + roles + "&reportname=" + BIRTfile.getTitle()); } catch (Exception e) { Logger.error(getClass().getName(), e.getMessage()); } }
From source file:com.glaf.base.modules.todo.job.TodoQuartzJob.java
public void sendMessageToAllUsersViaJSP() { try {/*from ww w . j a va2 s . c om*/ if (sendMessageServiceUrl != null) { URL url = new URL(sendMessageServiceUrl); URLConnection con = url.openConnection(); con.setDoOutput(true); InputStream in = con.getInputStream(); in = new BufferedInputStream(in); Reader r = new InputStreamReader(in); int c; logger.debug("==============Beging===================="); while ((c = r.read()) != -1) { logger.debug((char) c); } in.close(); logger.debug("===============End======================"); } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } }
From source file:jfix.util.Urls.java
/** * Returns content from given url as string. The url can contain * username:password after the protocol, so that basic authorization is * possible./*from w w w .j a va 2 s .c om*/ * * Example for url with basic authorization: * * http://username:password@www.domain.org/index.html */ public static String readString(String url, int timeout) { Reader reader = null; try { URLConnection uc = new URL(url).openConnection(); if (uc instanceof HttpURLConnection) { HttpURLConnection httpConnection = (HttpURLConnection) uc; httpConnection.setConnectTimeout(timeout * 1000); httpConnection.setReadTimeout(timeout * 1000); } Matcher matcher = Pattern.compile("://(\\w+:\\w+)@").matcher(url); if (matcher.find()) { String auth = matcher.group(1); String encoding = Base64.getEncoder().encodeToString(auth.getBytes()); uc.setRequestProperty("Authorization", "Basic " + encoding); } String charset = (uc.getContentType() != null && uc.getContentType().contains("charset=")) ? uc.getContentType().split("charset=")[1] : "utf-8"; reader = new BufferedReader(new InputStreamReader(uc.getInputStream(), charset)); StringBuilder sb = new StringBuilder(); for (int chr; (chr = reader.read()) != -1;) { sb.append((char) chr); } return sb.toString(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } } } }
From source file:com.netcracker.ejb.MapBean.java
private String readAll(final Reader rd) throws IOException { final StringBuilder sb = new StringBuilder(); int cp;/* w ww . j a v a 2 s . c o m*/ while ((cp = rd.read()) != -1) { sb.append((char) cp); } return sb.toString(); }
From source file:mupomat.utility.LongLatService.java
public void getLongitudeLatitude(String address) { try {/* www. j a v a 2s .c o m*/ StringBuilder urlBuilder = new StringBuilder(GEOCODE_REQUEST_URL); if (StringUtils.isNotBlank(address)) { urlBuilder.append("&address=").append(URLEncoder.encode(address, "UTF-8")); } final GetMethod getMethod = new GetMethod(urlBuilder.toString()); try { httpClient.executeMethod(getMethod); Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()); int data = reader.read(); char[] buffer = new char[1024]; Writer writer = new StringWriter(); while ((data = reader.read(buffer)) != -1) { writer.write(buffer, 0, data); } String result = writer.toString(); System.out.println(result.toString()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader("<" + writer.toString().trim())); Document doc = db.parse(is); strLatitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lat/text()"); System.out.println("Latitude:" + strLatitude); strLongtitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lng/text()"); System.out.println("Longitude:" + strLongtitude); } finally { getMethod.releaseConnection(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:jp.aegif.nemaki.util.YamlManager.java
public Object loadYml() { InputStream is = getClass().getClassLoader().getResourceAsStream(baseModelFile); if (is == null) { log.error("yaml file not found"); }//from ww w . j a v a 2 s . c o m Reader reader; try { reader = new InputStreamReader(is, "UTF-8"); reader = new BufferedReader(reader); StringBuffer buf = new StringBuffer(); int ch; while ((ch = reader.read()) >= 0) buf.append((char) ch); reader.close(); Object ydoc = YAML.load(buf.toString()); return ydoc; } catch (Exception e) { log.error(baseModelFile + " load failed", e); } return null; }
From source file:com.dnastack.ga4gh.impl.BeaconizeVariantImpl.java
/** * Queries the Variant API implementation for variants at the given position * * @param reference The reference (or chromosome) * @param position Position on the reference * @param alt The alternate allele to match against (currently not supported by GASearchVariantsRequest) * @return A JSON Object containing a GASearchVariantsResponse * @throws IOException Problems contacting API * @throws ParseException Problems parsing response *//*from www . java2 s . com*/ private JSONObject submitVariantSearchRequest(String reference, long position, String alt) throws IOException, ParseException { JSONObject obj = new JSONObject(); JSONArray list = new JSONArray(); list.addAll(Arrays.asList(variantSetIds)); obj.put("variantSetIds", list); obj.put("referenceName", reference); obj.put("start", position); obj.put("end", (position + 1)); String json = obj.toJSONString(); URL url = new URL(fullVariantSearchURL); StringBuilder postData = new StringBuilder(); postData.append(json); byte[] postDataBytes = postData.toString().getBytes("UTF-8"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); conn.setDoOutput(true); conn.getOutputStream().write(postDataBytes); StringBuilder sb = new StringBuilder(); Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); for (int c; (c = in.read()) >= 0;) { sb.append((char) c); } String jsonString = sb.toString(); return (JSONObject) JSONValue.parseWithException(jsonString); }
From source file:CssCompressor.java
public CssCompressor(Reader in) throws IOException { // Read the stream... int c;/*from w w w . j a v a2 s . co m*/ while ((c = in.read()) != -1) { srcsb.append((char) c); } }