public DXFFeatureReader(
      URL url, String typeName, String srs, GeometryType geometryType, ArrayList dxfInsertsFilter)
      throws IOException, DXFParseException {
    CountingInputStream cis = null;
    DXFLineNumberReader lnr = null;

    try {
      cis = new CountingInputStream(url.openStream());
      lnr = new DXFLineNumberReader(new InputStreamReader(cis));
      theUnivers = new DXFUnivers(dxfInsertsFilter);
      theUnivers.read(lnr);
    } catch (IOException ioe) {
      log.error("Error reading data in datastore: ", ioe);
      throw ioe;
    } finally {
      if (lnr != null) {
        lnr.close();
      }
      if (cis != null) {
        cis.close();
      }
    }

    // Set filter point, line, polygon, defined in datastore typenames
    updateTypeFilter(typeName, geometryType, srs);
  }
 @Override
 @Nonnull
 public OffsetInfo next() {
   try {
     long indexOffset = countingInputStream.getByteCount();
     int keysize = input.readUnsignedShort();
     input.skipBytes(keysize);
     Long dataOffset = input.readLong();
     skipPromotedIndexes();
     return new OffsetInfo(dataOffset, indexOffset);
   } catch (IOException e) {
     throw new IOError(e);
   }
 }
 @Override
 public void close() throws IOException {
   inReader.close();
   countingIn.close();
 }
 @Override
 public int read(char[] cbuf, int off, int len) throws IOException {
   int res = inReader.read(cbuf, off, len);
   monitor.reportProgress(countingIn.getByteCount());
   return res;
 }
Example #5
0
  /**
   * Start the parsing the file passed as parameter.
   *
   * @param file File to be parsed.
   * @param progress Progress listener used to show the percent of completed task.
   * @throws FileNotFoundException
   * @throws IOException
   * @throws InvalidFormatException
   */
  public void parse(File file, ProgressListener progress)
      throws FileNotFoundException, IOException, InvalidFormatException {
    if (!file.exists())
      throw new FileNotFoundException("File does not exists: " + file.getAbsolutePath());

    HashSet<String> addedElements = new HashSet<>();

    try (final CountingInputStream cntIs = new CountingInputStream(new FileInputStream(file));
        final BufferedReader reader = new BufferedReader(new InputStreamReader(cntIs))) {
      String line;
      while ((line = reader.readLine()) != null && (line.startsWith("##") || line.isEmpty())) {}

      if (line == null) throw new InvalidFormatException("File is empty");

      Hashtable<String, Integer> header = parseHeader(line);

      if (!header.containsKey(CHRPOS)
          || !header.containsKey(ALLELES)
          || !header.containsKey(ALLALLELECOUNT))
        throw new InvalidFormatException("Header does not contain all necessary fields");

      this.reader.setUp();

      long length = file.length();

      if (progress != null) progress.start(file.getAbsolutePath(), length);

      long stime = (new Date()).getTime();
      long seconds = 0;
      int percent = -1;
      while ((line = reader.readLine()) != null) {
        if (line.isEmpty() || line.startsWith("#")) continue;

        final String elements[] = line.split(DELIMITER);
        if (elements.length != header.size())
          throw new InvalidFormatException("Element does not have the same header size");

        final String chromosomePosition = elements[header.get(CHRPOS)];
        final String alleles = elements[header.get(ALLELES)];
        final String allAlleleCount = elements[header.get(ALLALLELECOUNT)];

        final String hash = chromosomePosition + alleles;
        if (!addedElements.contains(hash)) {
          readElement(chromosomePosition, alleles, allAlleleCount);
          addedElements.add(hash);
        }

        float readLength = cntIs.getByteCount();
        int newPercent = (int) ((readLength / length) * 100);

        long diff = (new Date()).getTime() - stime;
        long elapsedSeconds = diff / 1000;

        if (percent != newPercent || seconds < elapsedSeconds) {
          seconds = elapsedSeconds;
          percent = newPercent;
          if (progress != null)
            progress.progress(file.getAbsolutePath(), percent, seconds, (long) readLength);
        }
      }

      if (progress != null) progress.end(file.getAbsolutePath());
    } finally {
      this.reader.end();
    }
  }