List of usage examples for java.io BufferedReader ready
public boolean ready() throws IOException
From source file:gestionale.persistence.DAOSalva.java
public void scriviContratto() { File file = new File("ProvaContratto.docx"); List<String> listaStringhe = new ArrayList<String>(); try {//from www . ja v a 2 s .c o m BufferedReader br = new BufferedReader(new FileReader(file)); try { while (br.ready()) { try { listaStringhe.add(br.readLine()); } catch (IOException ex) { logger.info("IOException: " + ex.getMessage()); } } br.close(); } catch (IOException ex) { logger.info("IOException: " + ex.getMessage()); } //PrintStream ps = new PrintStream(new FileOutputStream(file)); logger.info("Valore di listaStringhe in posizione 3: " + listaStringhe.get(2)); // for(int i = 0; i < listaStringhe.size(); i++) { // // } } catch (FileNotFoundException ex) { logger.info("FileNotFoundException: " + ex.getMessage()); } }
From source file:edu.uci.ics.jung.io.CustomPajekNetReader.java
/** * Returns the first line read from <code>br</code> for which <code>p</code> * returns <code>true</code>, or <code>null</code> if there is no such line. * * @throws IOException/*from www . j a va 2 s . c om*/ */ protected String skip(BufferedReader br, Predicate<String> p) throws IOException { while (br.ready()) { String curLine = br.readLine(); if (curLine == null) { break; } curLine = curLine.trim(); if (p.evaluate(curLine)) { return curLine; } } return null; }
From source file:com.tulskiy.musique.system.configuration.Configuration.java
@Deprecated public void loadFromCustomFormat(Reader reader) { try {/* w w w . ja v a 2s. c o m*/ BufferedReader r = new BufferedReader(reader); ArrayList<String> array = null; String key = null; while (r.ready()) { String line = r.readLine(); if (line == null) break; if (line.startsWith(" ") && array != null) { array.add(line.trim()); } else { if (array != null) { if (array.size() > 0) map.put(key, array); array = null; } int index = line.indexOf(':'); if (index == -1) continue; key = line.substring(0, index); String value = line.substring(index + 1).trim(); if (value.isEmpty()) { array = new ArrayList<String>(); } else { map.put(key, value); } } } if (array != null) map.put(key, array); } catch (IOException e) { logger.severe("Failed to load configuration: " + e.getMessage()); } }
From source file:net.sensemaker.snappy.calendar.SnappyCalendar.java
private void renderCss(HTMLWriter writer) throws IOException { InputStream stream = this.getClass().getClassLoader() .getResourceAsStream("net/sensemaker/snappy/resources/snappy.css"); BufferedReader in = null; try {/* w w w . j a v a 2 s . c om*/ in = new BufferedReader(new InputStreamReader(stream)); writer.startElement("style"); while (in.ready()) { writer.writeText(in.readLine() + '\n'); } writer.endElement("style"); } finally { if (in != null) { in.close(); } } }
From source file:com.gnip.test.YouTubeEDCSerDeTest.java
@Test public void Tests() throws Exception { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); InputStream is = YouTubeEDCSerDeTest.class.getResourceAsStream("/YoutubeEDC.xml"); if (is == null) System.out.println("null"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); ObjectMapper jsonMapper = new ObjectMapper(); try {/*from w w w . ja va 2 s . c o m*/ while (br.ready()) { String line = br.readLine(); //LOGGER.debug(line); Object activityObject = xmlMapper.readValue(line, Object.class); String jsonObject = jsonMapper.writeValueAsString(activityObject); //LOGGER.debug(jsonObject); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }
From source file:edu.du.penrose.systems.fedoraApp.batchIngest.data.BatchIngestXMLhandlerImpl.java
/** * @see BatchIngestXMLhandler#markCurrentDocumentAsFailed() *//*from w ww . j a va 2s . c o m*/ public void markCurrentDocumentAsFailedMovePcos() throws FatalException { FileInputStream batchFileInputStream; try { // attempt to move PCOs listed in the xml file to the failed folder. We don't throw an exception since they may not even exist. batchFileInputStream = new FileInputStream(this.currentXmlFile); DataInputStream batchFileDataInputStream = new DataInputStream(batchFileInputStream); BufferedReader batchFileBufferedReader = new BufferedReader( new InputStreamReader(batchFileDataInputStream)); String oneLine = null; while (batchFileBufferedReader.ready()) { oneLine = batchFileBufferedReader.readLine(); if (oneLine.contains("LOCTYPE") && oneLine.contains("mets:FLocat")) { int fileIdPos = oneLine.indexOf("LOCTYPE"); int firstQuote = oneLine.indexOf(QUOTE, fileIdPos); if (firstQuote == -1) { firstQuote = oneLine.indexOf(APOST, fileIdPos); } int lastQuote = oneLine.indexOf(QUOTE, firstQuote + 1); if (lastQuote == -1) { lastQuote = oneLine.indexOf(APOST, firstQuote + 1); } String fileName = oneLine.substring(firstQuote + 1, lastQuote).trim(); fileName.replaceFirst("file:", ""); String newLocatonFileDirectory = this.urlHandler.getFilesFolderURL().getFile().replace('/', File.separatorChar); File pcoFile = new File(newLocatonFileDirectory + File.separator + fileName); BatchIngestURLhandler.transferFileToUrlWithUniqueName(pcoFile, this.urlHandler.getFailedFilesFolderURL()); } } } catch (Exception e) { logger.equals("Error while trying to move PCOs after batch failure:" + e.getMessage()); } markCurrentDocumentAsFailed(); }
From source file:org.wso2.appcloud.provisioning.runtime.beans.DeploymentLogStream.java
public String getLogContent(String replicaName) throws RuntimeProvisioningException { BufferedReader reader = deploymentLogs.get(replicaName); if (reader == null) { String msg = "Log stream for the replica name cannot be found."; log.error(msg);/*from w ww .j a v a 2s .com*/ throw new RuntimeProvisioningException(msg); } try { StringBuilder stringBuilder = new StringBuilder(); String line = null; boolean isReady = false; try { isReady = reader.ready(); } catch (IOException e) { //Ignore exception isReady = false; } if (isReady) { line = reader.readLine(); } while (line != null) { stringBuilder.append(line); stringBuilder.append("\n"); try { isReady = reader.ready(); } catch (IOException e) { //Ignore exception isReady = false; } if (!isReady) { break; } line = reader.readLine(); } return stringBuilder.toString(); } catch (IOException e) { String msg = "Error occurred while reading log line from the log stream."; log.error(msg, e); throw new RuntimeProvisioningException(msg, e); } }
From source file:com.gnip.test.YoutubeEDCAsActivityTest.java
@Test @Ignore//w ww . jav a 2 s . co m public void Tests() throws Exception { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); InputStream is = YoutubeEDCAsActivityTest.class.getResourceAsStream("/YoutubeEDC.xml"); if (is == null) System.out.println("null"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); ObjectMapper jsonMapper = new ObjectMapper(); try { while (br.ready()) { String line = br.readLine(); //LOGGER.debug(line); Object activityObject = xmlMapper.readValue(line, Object.class); String jsonString = jsonMapper.writeValueAsString(activityObject); JSONObject jsonObject = new JSONObject(jsonString); JSONObject fixedObject = GnipActivityFixer.fix(jsonObject); Activity activity = jsonMapper.readValue(fixedObject.toString(), Activity.class); //LOGGER.debug(des); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }
From source file:org.sakaiproject.kernel.component.core.PersistenceUnitClassLoader.java
private String readFile(URL url) { StringBuilder sb = new StringBuilder(); try {//w w w.ja v a 2 s. c om BufferedReader br = new BufferedReader(new FileReader(new File(url.toURI()))); while (br.ready()) { sb.append(br.readLine()).append("\n"); } br.close(); } catch (RuntimeException e) { // do nothing } catch (Exception e) { // do nothing } return sb.toString(); }
From source file:org.apache.streams.gnip.flickr.test.FlickrEDCAsActivityTest.java
@Ignore @Test/*from w w w.j a v a 2 s .c om*/ public void Tests() throws Exception { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); InputStream is = FlickrEDCAsActivityTest.class.getResourceAsStream("/FlickrEDC.xml"); if (is == null) System.out.println("null"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); ObjectMapper jsonMapper = new ObjectMapper(); try { while (br.ready()) { String line = br.readLine(); //LOGGER.debug(line); Object activityObject = xmlMapper.readValue(line, Object.class); String jsonString = jsonMapper.writeValueAsString(activityObject); JSONObject jsonObject = new JSONObject(jsonString); JSONObject fixedObject = GnipActivityFixer.fix(jsonObject); Activity activity = null; try { activity = jsonMapper.readValue(fixedObject.toString(), Activity.class); } catch (Exception e) { LOGGER.error(jsonObject.toString()); LOGGER.error(fixedObject.toString()); e.printStackTrace(); Assert.fail(); } //LOGGER.debug(des); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }