List of usage examples for org.apache.commons.io IOUtils lineIterator
public static LineIterator lineIterator(Reader reader)
Reader
. From source file:edu.umn.msi.tropix.proteomics.test.VerifyUtils.java
public static void verifyMGF(final InputStream stream) { final LineIterator lineIterator = IOUtils.lineIterator(new InputStreamReader(stream)); assert lineIterator.hasNext(); String line = lineIterator.nextLine(); assert line.startsWith("COM="); assert lineIterator.hasNext(); line = lineIterator.nextLine();/* w w w . j a v a 2 s .c om*/ assert line.startsWith("CHARGE="); while (true) { if (!lineIterator.hasNext()) { break; } line = lineIterator.nextLine(); assert line.equals("BEGIN IONS") : line; line = lineIterator.nextLine(); assert line.matches( "PEPMASS=(\\d*\\.?\\d*)( (\\d*\\.?\\d*))?") : "Does not appear to be a peptide mass line " + line; line = lineIterator.nextLine(); assert line.matches("CHARGE=[\\d, \\+]+") : line; line = lineIterator.nextLine(); assert line.startsWith("SCANS=") : line; line = lineIterator.nextLine(); assert line.startsWith("TITLE=") : line; while (true) { line = lineIterator.nextLine(); if (line.equals("END IONS")) { break; } else if (line .matches(RegexUtils.FLOATING_POINT_LITERAL + "\\s+" + RegexUtils.FLOATING_POINT_LITERAL)) { continue; } else { assert false : "MGF contains invalid line " + line; } } } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.internal.model.BratAnnotationDocument.java
public static BratAnnotationDocument read(Reader aReader) { BratAnnotationDocument doc = new BratAnnotationDocument(); List<BratEventAnnotation> events = new ArrayList<>(); // Read from file LineIterator lines = IOUtils.lineIterator(aReader); while (lines.hasNext()) { String line = lines.next(); switch (line.charAt(0)) { case 'T': doc.addAnnotation(BratTextAnnotation.parse(line)); break; case 'A': case 'M': doc.addAttribute(BratAttribute.parse(line)); break; case 'R': doc.addAnnotation(BratRelationAnnotation.parse(line)); break; case 'E': { BratEventAnnotation e = BratEventAnnotation.parse(line); events.add(e);//from w w w . j av a 2 s . c o m doc.addAnnotation(e); break; } default: throw new IllegalStateException("Unknown annotation format: [" + line + "]"); } } // Attach attributes to annotations for (BratAttribute attr : doc.attributes.values()) { BratAnnotation target = doc.annotations.get(attr.getTarget()); if (target == null) { throw new IllegalStateException( "Attribute refers to unknown annotation [" + attr.getTarget() + "]"); } target.addAttribute(attr); } // FIXME this is currently inconsistent between reading and manual creation / writing // when we read the triggers, they no longer appear as individual annotations // when we manually create the brat annotations, we leave the triggers // Attach triggers to events and remove them as individual annotations List<String> triggersIds = new ArrayList<>(); for (BratEventAnnotation event : events) { BratTextAnnotation trigger = (BratTextAnnotation) doc.annotations.get(event.getTrigger()); if (trigger == null) { throw new IllegalStateException( "Trigger refers to unknown annotation [" + event.getTrigger() + "]"); } triggersIds.add(trigger.getId()); event.setTriggerAnnotation(trigger); } // Remove trigger annotations, they are owned by the event doc.annotations.keySet().removeAll(triggersIds); return doc; }
From source file:net.femtoparsec.jwhois.JWhoIsTest.java
private static void dumpAsText(byte[] bytes) { LineIterator iterator = IOUtils.lineIterator(new InputStreamReader(new ByteArrayInputStream(bytes))); while (iterator.hasNext()) { System.out.println(iterator.nextLine()); }// w w w.j av a2 s . c om }
From source file:net.femtoparsec.jwhois.utils.ByteUtils.java
/** * Convert an array of bytes to an array of lines * @param data the given array of bytes// w w w. ja v a2s. co m * @return an array of string */ public static String[] bytesToStrings(byte[] data) { if (data == null) { return null; } ByteArrayInputStream inputStream = new ByteArrayInputStream(data); LineIterator lineIterator = IOUtils.lineIterator(new InputStreamReader(inputStream)); List<String> lines = new LinkedList<String>(); while (lineIterator.hasNext()) { lines.add(lineIterator.nextLine()); } return lines.toArray(new String[lines.size()]); }
From source file:com.thoughtworks.go.util.command.StreamPumper.java
public void run() { try (LineIterator lineIterator = IOUtils.lineIterator(in)) { while (lineIterator.hasNext()) { consumeLine(lineIterator.nextLine()); }/*from w ww .j av a 2 s . co m*/ } catch (Exception ignore) { } finally { completed = true; } }
From source file:mitm.common.util.NameValueLineIterator.java
public NameValueLineIterator(Reader reader) throws IOException { lineIterator = IOUtils.lineIterator(reader); }
From source file:edu.umn.msi.tropix.proteomics.test.VerifyUtils.java
public static void verifyDTAList(final DTAList dtaList) { for (final DTAList.Entry entry : dtaList) { final byte[] bytes = entry.getContents(); final LineIterator lineIterator = IOUtils.lineIterator(new StringReader(new String(bytes))); final String firstLine = lineIterator.nextLine(); assert firstLine.matches("^\\d+\\.\\d+\\s+\\d+\\s*$"); while (lineIterator.hasNext()) { final String line = lineIterator.nextLine(); assert line.matches(RegexUtils.FLOATING_POINT_LITERAL + "\\s+" + RegexUtils.FLOATING_POINT_LITERAL + "\\s*") : "Line is not of form -- <double> <double>"; }// w w w. j a va2 s . c om final String name = entry.getName(); assert name.matches("^.*\\.\\d+\\.\\d+\\.\\d+\\.[dD][tT][aA]$"); } }
From source file:it.drwolf.ridire.util.JumpToLine.java
/** * Opens any underlying streams/readers and immeadietly seeks to the line in * the file that's next to be read; skipping over lines in the file this * reader has already read./*w w w. j a va 2 s . co m*/ */ public void open() throws IOException { try { this.isr_ = new InputStreamReader(new FileInputStream(this.file_)); this.it_ = IOUtils.lineIterator(this.isr_); } catch (Exception e) { this.close(); throw new IOException(e); } }
From source file:io.druid.firehose.google.StaticGoogleBlobStoreFirehoseFactory.java
@Override public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException { Preconditions.checkNotNull(storage, "null storage"); final LinkedList<GoogleBlob> objectQueue = Lists.newLinkedList(blobs); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override/*from ww w .ja va2 s . c o m*/ public boolean hasNext() { return !objectQueue.isEmpty(); } @Override public LineIterator next() { final GoogleBlob nextURI = objectQueue.poll(); final String bucket = nextURI.getBucket(); final String path = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath(); try { final InputStream innerInputStream = new GoogleByteSource(storage, bucket, path).openStream(); final InputStream outerInputStream = path.endsWith(".gz") ? CompressionUtils.gzipInputStream(innerInputStream) : innerInputStream; return IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (Exception e) { LOG.error(e, "Exception opening bucket[%s] blob[%s]", bucket, path); throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, stringInputRowParser); }
From source file:io.druid.firehose.azure.StaticAzureBlobStoreFirehoseFactory.java
@Override public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException { Preconditions.checkNotNull(azureStorage, "null azureStorage"); final LinkedList<AzureBlob> objectQueue = Lists.newLinkedList(blobs); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override/* www . j a va 2s .c o m*/ public boolean hasNext() { return !objectQueue.isEmpty(); } @Override public LineIterator next() { final AzureBlob nextURI = objectQueue.poll(); final String container = nextURI.getContainer(); final String path = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath(); try { final InputStream innerInputStream = new AzureByteSource(azureStorage, container, path) .openStream(); final InputStream outerInputStream = path.endsWith(".gz") ? CompressionUtils.gzipInputStream(innerInputStream) : innerInputStream; return IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (Exception e) { log.error(e, "Exception opening container[%s] blob[%s]", container, path); throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, stringInputRowParser); }