List of usage examples for java.io BufferedReader ready
public boolean ready() throws IOException
From source file:org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader.java
public void run() { InputStreamReader inputStreamReader = null; try {/*from w ww . jav a 2s.c om*/ inputStreamReader = new InputStreamReader(inputStream, Charset.defaultCharset()); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (running) { if (bufferedReader.ready()) { String s = bufferedReader.readLine(); stringBuilder.setLength(0); if (s == null) { break; } if (STREAM_TYPE_IN.equals(streamType)) { stringBuilder.append(s).append("\n"); log.info(s); } else if (STREAM_TYPE_ERROR.equals(streamType)) { stringBuilder.append(s).append("\n"); log.error(s); } } } } catch (Exception ex) { log.error("Problem reading the [" + streamType + "] due to: " + ex.getMessage(), ex); } finally { if (inputStreamReader != null) { try { inputStream.close(); } catch (IOException e) { log.error("Error occurred while closing the server log stream: " + e.getMessage(), e); } } } }
From source file:org.apache.streams.twitter.test.InstagramActivitySerDeTest.java
@Test public void TestMediaFeedObjects() { InstagramDeserializer instagramDeserializer = new InstagramDeserializer(""); InputStream is = InstagramActivitySerDeTest.class.getResourceAsStream("/testMediaFeedObjects.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); try {//from w w w .j a va 2 s .co m while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { LOGGER.info("raw: {}", line); MediaFeedData mediaFeedData = instagramDeserializer .createObjectFromResponse(MediaFeedData.class, line); Activity activity = new Activity(); LOGGER.info("activity: {}", activity.toString()); updateActivity(mediaFeedData, activity); assertThat(activity, is(not(nullValue()))); assertThat(activity.getId(), is(not(nullValue()))); assertThat(activity.getActor(), is(not(nullValue()))); assertThat(activity.getActor().getId(), is(not(nullValue()))); assertThat(activity.getVerb(), is(not(nullValue()))); assertThat(activity.getProvider(), is(not(nullValue()))); } } } catch (Exception e) { System.out.println(e); e.printStackTrace(); Assert.fail(); } }
From source file:ffx.potential.parsers.INTFileFilter.java
/** * <p>// ww w. ja va2 s . co m * acceptDeep</p> * * @param parm a {@link java.io.File} object. * @return a boolean. */ public boolean acceptDeep(File parm) { try { if (parm == null || parm.isDirectory() || !parm.canRead()) { return false; } FileReader fr = new FileReader(parm); BufferedReader br = new BufferedReader(fr); if (!br.ready()) { // Empty File? return false; } // If the first token is not an integer this file is not // an Internal Coordinates File. String rawdata = br.readLine(); String header[] = rawdata.trim().split(" +"); if (header == null || header.length == 0) { return false; } try { Integer.parseInt(header[0]); } catch (Exception e) { return false; } // If the the first Atom line does not begin with an integer and // contain // three tokens, it is not an internal coordinate file. String firstAtom = br.readLine(); if (firstAtom == null) { return false; } br.close(); fr.close(); String data[] = firstAtom.trim().split(" +"); if (data == null || data.length != 3) { return false; } try { Integer.parseInt(data[0]); } catch (Exception e) { return false; } return true; } catch (Exception e) { return true; } }
From source file:com.google.gplus.processor.GooglePlusActivitySerDeIT.java
@Test @SuppressWarnings("unchecked") public void testActivityObjects() { InputStream is = GooglePlusActivitySerDeIT.class.getResourceAsStream("/google_plus_activity_jsons.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); try {// w w w. jav a 2 s. co m while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { LOGGER.info("raw: {}", line); Activity activity = new Activity(); com.google.api.services.plus.model.Activity googlePlusActivity = objectMapper.readValue(line, com.google.api.services.plus.model.Activity.class); GooglePlusActivityUtil.updateActivity(googlePlusActivity, activity); LOGGER.info("activity: {}", activity); assertNotNull(activity); assert (activity.getId().contains("id:googleplus:post")); assertEquals(activity.getVerb(), "post"); Provider provider = activity.getProvider(); assertEquals(provider.getId(), "id:providers:googleplus"); assertEquals(provider.getDisplayName(), "GooglePlus"); ActivityObject actor = activity.getActor(); assertNotNull(actor.getImage()); assert (actor.getId().contains("id:googleplus:")); assertNotNull(actor.getUrl()); assertNotNull(activity.getPublished()); assertNotNull(activity.getTitle()); assertNotNull(activity.getUrl()); Map<String, Object> extensions = ExtensionUtil.getInstance().getExtensions(activity); assertNotNull(extensions); if (activity.getContent() != null) { assertNotNull(extensions.get("rebroadcasts")); assertNotNull(extensions.get("keywords")); assertNotNull(extensions.get("likes")); assert (((Map<String, Object>) extensions.get("rebroadcasts")).containsKey("count")); assert (((Map<String, Object>) extensions.get("likes")).containsKey("count")); } } } } catch (Exception ex) { LOGGER.error("Exception while testing serializability: {}", ex); } }
From source file:org.wso2.carbon.automation.extensions.servers.utils.InputStreamHandler.java
public void run() { InputStreamReader inputStreamReader = null; try {/* ww w . j a va2 s . com*/ inputStreamReader = new InputStreamReader(inputStream, "ISO-8859-1"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (true) { if (bufferedReader.ready()) { String s = bufferedReader.readLine(); stringBuilder.setLength(0); if (s == null) { break; } if (STREAM_TYPE_IN.equals(streamType)) { stringBuilder.append(s).append("\n"); log.info(s); } else if (STREAM_TYPE_ERROR.equals(streamType)) { stringBuilder.append(s).append("\n"); log.error(s); } } } } catch (Exception ex) { log.error("Problem reading the [" + streamType + "] due to: " + ex.getMessage(), ex); } finally { if (inputStreamReader != null) { try { inputStream.close(); } catch (IOException e) { log.error("Error occured while closing the stream: " + e.getMessage(), e); } } } }
From source file:ffx.potential.parsers.XYZFileFilter.java
/** * <p>/*from w ww .ja va 2 s . co m*/ * acceptDeep</p> * * @param file a {@link java.io.File} object. * @return a boolean. */ public boolean acceptDeep(File file) { try { if (file == null || file.isDirectory() || !file.canRead()) { return false; } FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); if (!br.ready()) { return false; } /** * If the first token is not an integer this file is not a TINKER * Cartesian Coordinate File. */ String rawdata = br.readLine(); String header[] = rawdata.trim().split(" +"); if (header == null || header.length == 0) { return false; } try { Integer.parseInt(header[0]); } catch (Exception e) { return false; } /** * If the the first Atom line does not begin with an integer and * contain at least six tokens, this is not a TINKER cartesian * coordinate file. * */ String firstAtom = br.readLine(); if (firstAtom == null) { return false; } br.close(); fr.close(); String data[] = firstAtom.trim().split(" +"); if (data == null || data.length < 6) { return false; } try { Integer.parseInt(data[0]); } catch (Exception e) { return false; } return true; } catch (Exception e) { return true; } }
From source file:org.wso2.carbon.integration.common.extensions.utils.InputStreamHandler.java
public void run() { InputStreamReader inputStreamReader = null; try {// w ww. j a v a 2s . c o m inputStreamReader = new InputStreamReader(inputStream, "ISO-8859-1"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (running) { if (bufferedReader.ready()) { String s = bufferedReader.readLine(); stringBuilder.setLength(0); if (s == null) { break; } if (STREAM_TYPE_IN.equals(streamType)) { stringBuilder.append(s).append("\n"); log.info(s); } else if (STREAM_TYPE_ERROR.equals(streamType)) { stringBuilder.append(s).append("\n"); log.error(s); } } } } catch (Exception ex) { log.error("Problem reading the [" + streamType + "] due to: " + ex.getMessage(), ex); } finally { if (inputStreamReader != null) { try { inputStream.close(); } catch (IOException e) { log.error("Error occured while closing the stream: " + e.getMessage(), e); } } } }
From source file:org.camunda.bpm.ext.sdk.impl.ClientCommandContext.java
public HttpResponse execute(HttpRequestBase req) { HttpResponse response = null;/*from w w w. jav a 2s.c o m*/ try { response = httpClient.execute(req); } catch (HttpHostConnectException e) { throw new CamundaClientException( "Unable to connect to host " + req.getURI().getHost() + ". Full uri=" + req.getURI(), e); } catch (Exception e) { throw new CamundaClientException("Exception while executing request", e); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { HttpEntity entity = response.getEntity(); String responseStr = ""; try { InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); while (reader.ready()) { responseStr += reader.readLine(); } } catch (Exception e) { e.printStackTrace(); } throw new CamundaClientException( "Request " + req + " returned error: " + response.getStatusLine() + ": " + responseStr); } return response; }
From source file:org.sakaiproject.evaluation.tool.settings.ConfigSettingsPropertiesFileParser.java
/** * @return "uploadSuccess" if the parsing was completed without issue. Otherwise, return "uploadFailure". *///from w w w. jav a2s. c o m public String parse() { MultipartFile file = (MultipartFile) multipartMap.get("configFile"); HashMap<String, String> result = new HashMap<>(); /* We manually parse the properties file rather than using the java.util.Properties due to the keys having a ':' in * the string (':' is one of the three valid separator values in the Java properties file definition). */ BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(file.getInputStream())); while (reader.ready()) { String linein = reader.readLine(); String[] keyValuePair = linein.split("="); result.put(keyValuePair[0], keyValuePair[1]); } } catch (IOException ioe) { LOG.error("Error reading uploaded properties file for overwrite settings", ioe); return "uploadFailure"; } finally { IOUtils.closeQuietly(reader); } // Update the producer so it can show the results on the html template importConfigProducer.setUploadedConfigValues(result); // Update the handler so the settings can be saved if the user chooses to do so overwriteSettingHandler.setUploadedConfigValues(result); return "uploadSuccess"; }
From source file:de.rinderle.softvis3d.layout.dot.ExecuteCommand.java
private String readOutputStream(final InputStream inputStream) throws IOException { String result = ""; final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); if (reader.ready()) { String line;/* w ww .j a va 2 s. c o m*/ while ((line = reader.readLine()) != null) { result += line; } reader.close(); } return result; }