List of usage examples for java.io BufferedReader ready
public boolean ready() throws IOException
From source file:de.qucosa.repository.FedoraRepository.java
public Map<String, RelsExtPredicateEnum> identifyReferencingObjects(RelsExtPredicateEnum predicate, String referencedId) {/*from ww w. j a v a2 s .c o m*/ final LinkedHashMap<String, RelsExtPredicateEnum> resultMap = new LinkedHashMap<>(); final String query = String.format("select distinct ?source where {" + " ?target <dc:identifier> '%1$s' ." + " ?target <dc:identifier> ?refliteral ." + " ?source <fedora-rels-ext:%2$s> ?refiri" + " filter (regex(str(?refiri), str(?refliteral)))}", referencedId, predicate); RiSearchResponse riSearchResponse = null; try { RiSearch riSearch = new RiSearch(query).format("csv"); riSearchResponse = riSearch.execute(fedoraClient); BufferedReader b = new BufferedReader(new InputStreamReader(riSearchResponse.getEntityInputStream())); b.readLine(); while (b.ready()) { final String line = b.readLine(); final String pid = line.substring(line.indexOf('/') + 1); resultMap.put(pid, predicate); } } catch (IOException | ArrayIndexOutOfBoundsException e) { log.warn("Failed to parse Fedora Resource Index result", e); } catch (FedoraClientException e) { log.warn("Failed querying Fedora Resource Index", e); } finally { if (riSearchResponse != null) riSearchResponse.close(); } return resultMap; }
From source file:de.tarent.maven.plugins.pkg.Utils.java
/** * This method can be used to debug the output of processes. * /* w ww . ja v a 2 s. c om*/ * @param p */ public static void print(Process p) { BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream())); try { while (br.ready()) { System.err.println("*** Process output ***"); System.err.println(br.readLine()); System.err.println("**********************"); } } catch (IOException ioe) { // foo } }
From source file:com.google.gplus.GooglePlusCommentSerDeTest.java
@org.junit.Test public void testCommentObjects() { InputStream is = GooglePlusPersonSerDeTest.class.getResourceAsStream("/google_plus_comments_jsons.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); Activity activity = new Activity(); List<Comment> comments = Lists.newArrayList(); try {//from ww w . j av a2 s . c om while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { LOGGER.info("raw: {}", line); Comment comment = objectMapper.readValue(line, Comment.class); LOGGER.info("comment: {}", comment); assertNotNull(comment); assertNotNull(comment.getEtag()); assertNotNull(comment.getId()); assertNotNull(comment.getInReplyTo()); assertNotNull(comment.getObject()); assertNotNull(comment.getPlusoners()); assertNotNull(comment.getPublished()); assertNotNull(comment.getUpdated()); assertNotNull(comment.getSelfLink()); assertEquals(comment.getVerb(), "post"); comments.add(comment); } } assertEquals(comments.size(), 3); googlePlusActivityUtil.updateActivity(comments, activity); assertNotNull(activity); assertNotNull(activity.getObject()); assertEquals(activity.getObject().getAttachments().size(), 3); } catch (Exception e) { LOGGER.error("Exception while testing serializability: {}", e); } }
From source file:org.trnltk.experiment.morphology.ambiguity.ParseResultReader.java
public List<WordParseResultEntry> getParseResultEntries(Reader reader) throws IOException, JSONException { final BufferedReader bufferedReader = new BufferedReader(reader); List<WordParseResultEntry> entries = new ArrayList<WordParseResultEntry>(); WordParseResultEntry currentEntry = null; while (bufferedReader.ready()) { final String line = bufferedReader.readLine(); if (line.startsWith("- word: ")) { final String word = line.substring("- word: ".length()); currentEntry = new WordParseResultEntry(word); entries.add(currentEntry);// ww w.j a v a2 s . c o m } else //noinspection StatementWithEmptyBody if (line.startsWith(" results:")) { // ok, go } else if (line.startsWith(" - ")) { final String result = line.substring(" - ".length()); final ParseResult objParseResult = this.createParseResultObject(result); assert currentEntry != null; currentEntry.addParseResult(objParseResult); } } bufferedReader.close(); return entries; }
From source file:fr.univlorraine.ecandidat.controllers.DemoController.java
/** Lance un script sql * @param script/*from w w w . ja v a 2s . c o m*/ */ @Transactional private void launchSqlScript(String script) { EntityManager em = entityManagerFactoryEcandidat.createEntityManager(); em.getTransaction().begin(); try { final InputStream inputStream = this.getClass().getResourceAsStream("/db/demo/" + script); final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); final BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (bufferedReader.ready()) { Query query = em.createNativeQuery(bufferedReader.readLine()); query.executeUpdate(); } } catch (Exception e) { em.getTransaction().rollback(); em.close(); } em.getTransaction().commit(); em.close(); }
From source file:com.google.gplus.GooglePlusCommentSerDeIT.java
@Test public void testCommentObjects() { InputStream is = GooglePlusCommentSerDeIT.class.getResourceAsStream("/google_plus_comments_jsons.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); Activity activity = new Activity(); List<Comment> comments = new ArrayList<>(); try {/*from www. j a v a 2 s.co m*/ while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { LOGGER.info("raw: {}", line); Comment comment = objectMapper.readValue(line, Comment.class); LOGGER.info("comment: {}", comment); assertNotNull(comment); assertNotNull(comment.getEtag()); assertNotNull(comment.getId()); assertNotNull(comment.getInReplyTo()); assertNotNull(comment.getObject()); assertNotNull(comment.getPlusoners()); assertNotNull(comment.getPublished()); assertNotNull(comment.getUpdated()); assertNotNull(comment.getSelfLink()); assertEquals(comment.getVerb(), "post"); comments.add(comment); } } assertEquals(comments.size(), 3); GooglePlusActivityUtil.updateActivity(comments, activity); assertNotNull(activity); assertNotNull(activity.getObject()); assertEquals(activity.getObject().getAttachments().size(), 3); } catch (Exception ex) { LOGGER.error("Exception while testing serializability: {}", ex); } }
From source file:org.n52.oxf.ses.adapter.client.SESConnectorImpl.java
private String parseError(InputStream instream) { StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(instream)); try {//from w w w . j a va 2 s.c o m while (br.ready()) { sb.append(br.readLine()); } } catch (IOException e) { logger.warn(e.getMessage(), e); } finally { try { instream.close(); } catch (IOException e) { logger.warn(e.getMessage(), e); } } return sb.toString(); }
From source file:org.apache.streams.twitter.test.TwitterObjectMapperTest.java
@Test public void Tests() { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); InputStream is = TwitterObjectMapperTest.class.getResourceAsStream("/testtweets.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); int tweetlinks = 0; int retweetlinks = 0; try {//from w w w . j av a2 s .c o m while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { LOGGER.info("raw: {}", line); Class detected = new TwitterDocumentClassifier().detectClasses(line).get(0); ObjectNode event = (ObjectNode) mapper.readTree(line); assertThat(event, is(not(nullValue()))); if (detected == Tweet.class) { Tweet tweet = mapper.convertValue(event, Tweet.class); assertThat(tweet, is(not(nullValue()))); assertThat(tweet.getCreatedAt(), is(not(nullValue()))); assertThat(tweet.getText(), is(not(nullValue()))); assertThat(tweet.getUser(), is(not(nullValue()))); tweetlinks += Optional.fromNullable(tweet.getEntities().getUrls().size()).or(0); } else if (detected == Retweet.class) { Retweet retweet = mapper.convertValue(event, Retweet.class); assertThat(retweet.getRetweetedStatus(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getCreatedAt(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getText(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getUser(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getUser().getId(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getUser().getCreatedAt(), is(not(nullValue()))); retweetlinks += Optional .fromNullable(retweet.getRetweetedStatus().getEntities().getUrls().size()).or(0); } else if (detected == Delete.class) { Delete delete = mapper.convertValue(event, Delete.class); assertThat(delete.getDelete(), is(not(nullValue()))); assertThat(delete.getDelete().getStatus(), is(not(nullValue()))); assertThat(delete.getDelete().getStatus().getId(), is(not(nullValue()))); assertThat(delete.getDelete().getStatus().getUserId(), is(not(nullValue()))); } else { Assert.fail(); } } } } catch (Exception e) { System.out.println(e); e.printStackTrace(); Assert.fail(); } assertThat(tweetlinks, is(greaterThan(0))); assertThat(retweetlinks, is(greaterThan(0))); }
From source file:bjerne.gallery.service.impl.VideoConversionServiceImpl.java
@Override public void convertVideo(File origVideo, File newVideo, String conversionMode) throws IOException { long startTime = System.currentTimeMillis(); if (newVideo.exists()) { LOG.debug("{} already exists. Trying to delete.", newVideo); newVideo.delete();/*from ww w. j a v a 2s . co m*/ } if (!newVideo.getParentFile().exists()) { boolean dirsCreated = newVideo.getParentFile().mkdirs(); if (!dirsCreated) { String errorMessage = String.format("Could not create all dirs for %s", newVideo); LOG.error(errorMessage); throw new IOException(errorMessage); } } ProcessBuilder pb = new ProcessBuilder(generateCommandParamList(origVideo, newVideo, conversionMode)); Process pr = null; Thread currentThread = Thread.currentThread(); try { LOG.debug("Adding current thread: {}", currentThread); registerThread(currentThread); pr = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(pr.getInputStream())); while (reader.ready()) { Thread.sleep(100); LOG.info("One line: {}", reader.readLine()); } boolean waitResult = pr.waitFor(maxWaitTimeSeconds, TimeUnit.SECONDS); if (!waitResult) { String errorMessage = String.format( "Waiting for video conversion exceeded maximum threshold of %s seconds", maxWaitTimeSeconds); LOG.error(errorMessage); cleanupFailure(pr, newVideo); throw new IOException(errorMessage); } long duration = System.currentTimeMillis() - startTime; LOG.debug("Time in milliseconds to resize {}: {}", newVideo.toString(), duration); } catch (InterruptedException ie) { cleanupFailure(pr, newVideo); LOG.error("Was interrupted while waiting for conversion. Throwing IOException"); throw new IOException(ie); } finally { unregisterThread(currentThread); } }
From source file:org.apache.streams.twitter.test.data.TwitterObjectMapperIT.java
@Test public void tests() { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); InputStream is = TwitterObjectMapperIT.class.getResourceAsStream("/testtweets.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); int tweetlinks = 0; int retweetlinks = 0; try {/*from w w w .j av a2 s .c om*/ while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { LOGGER.info("raw: {}", line); Class detected = new TwitterDocumentClassifier().detectClasses(line).get(0); ObjectNode event = (ObjectNode) mapper.readTree(line); assertThat(event, is(not(nullValue()))); if (detected == Tweet.class) { Tweet tweet = mapper.convertValue(event, Tweet.class); assertThat(tweet, is(not(nullValue()))); assertThat(tweet.getCreatedAt(), is(not(nullValue()))); assertThat(tweet.getText(), is(not(nullValue()))); assertThat(tweet.getUser(), is(not(nullValue()))); tweetlinks += Optional.ofNullable(tweet.getEntities().getUrls().size()).orElse(0); } else if (detected == Retweet.class) { Retweet retweet = mapper.convertValue(event, Retweet.class); assertThat(retweet.getRetweetedStatus(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getCreatedAt(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getText(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getUser(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getUser().getId(), is(not(nullValue()))); assertThat(retweet.getRetweetedStatus().getUser().getCreatedAt(), is(not(nullValue()))); retweetlinks += Optional .ofNullable(retweet.getRetweetedStatus().getEntities().getUrls().size()).orElse(0); } else if (detected == Delete.class) { Delete delete = mapper.convertValue(event, Delete.class); assertThat(delete.getDelete(), is(not(nullValue()))); assertThat(delete.getDelete().getStatus(), is(not(nullValue()))); assertThat(delete.getDelete().getStatus().getId(), is(not(nullValue()))); assertThat(delete.getDelete().getStatus().getUserId(), is(not(nullValue()))); } else { Assert.fail(); } } } } catch (Exception ex) { LOGGER.error("Exception: ", ex); Assert.fail(); } assertThat(tweetlinks, is(greaterThan(0))); assertThat(retweetlinks, is(greaterThan(0))); }