Package org.apache.commons.io.input

Examples of org.apache.commons.io.input.CountingInputStream


    private DXFUnivers theUnivers;
    private ArrayList dxfInsertsFilter;
    private int featureID = 0;

    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);
View Full Code Here


                    rs = null;
                }
            }
            MessageDigest digest = getDigest();
            DigestInputStream dIn = new DigestInputStream(stream, digest);
            CountingInputStream in = new CountingInputStream(dIn);
            StreamWrapper wrapper;
            if (STORE_SIZE_MINUS_ONE.equals(storeStream)) {
                wrapper = new StreamWrapper(in, -1);
            } else if (STORE_SIZE_MAX.equals(storeStream)) {
                wrapper = new StreamWrapper(in, Integer.MAX_VALUE);
            } else if (STORE_TEMP_FILE.equals(storeStream)) {
                File temp = moveToTempFile(in);
                long length = temp.length();
                wrapper = new StreamWrapper(new TempFileInputStream(temp, true), length);
            } else {
                throw new DataStoreException("Unsupported stream store algorithm: " + storeStream);
            }
            // UPDATE DATASTORE SET DATA=? WHERE ID=?
            conHelper.exec(updateDataSQL, wrapper, tempId);
            long length = in.getByteCount();
            DataIdentifier identifier = new DataIdentifier(digest.digest());
            usesIdentifier(identifier);
            String id = identifier.toString();
            long newModified;
            while (true) {
View Full Code Here

  public IndexedSSTableScanner(InputStream is,
      long end,
      Version version,
      DataInput indexInput) {
    super(is, end, version);
    this.is = new CountingInputStream(is);
    this.indexScanner = new IndexScanner(indexInput, version);
    this.nextRow = this.indexScanner.next();
  }
View Full Code Here

    this.input = input;
    this.version = version;
  }

  public OffsetScanner(InputStream is, String filename) {
    this.countingInputStream = new CountingInputStream(is);
    this.input = new DataInputStream(this.countingInputStream);
    this.version = Descriptor.fromFilename(filename).version;
  }
View Full Code Here

    FeatureCollection<?, ?> features;
    if (response instanceof ResponseFeatureCollection) {
      ResponseFeatureCollection responseFeatures = (ResponseFeatureCollection) response;
      features = responseFeatures.getFeatureCollection();
    } else {
      CountingInputStream counter = new CountingInputStream(response.getResultStream());
      features = (FeatureCollection<?, ?>)parseWfs(counter);
      m_rxGml += counter.getByteCount();
    }
   
    FeatureIterator<?> it = features.features();
    try {
      while (it.hasNext()) {
View Full Code Here

    }
  }

  private boolean processSha1SyncResponse(Response response) throws IOException {
    int expected = m_server.level() + 1;
    CountingInputStream counter = new CountingInputStream(response.getResultStream());
    InputStreamReader reader = new InputStreamReader(new BufferedInputStream(counter), UTF8.UTF8);
    try {
      m_server = new Gson().fromJson(reader, Sha1SyncJson.class);
      if (expected != m_server.level()) {
        throw new IllegalStateException("Level warp! expected("+expected+"), actual("+m_server.level()+")");
      }
      if (!versionFeatures.getToken().equals(m_server.version())) {
        throw new IllegalStateException("Version warp! expected("+versionFeatures.getToken()+"), actual("+m_server.version()+")");
      }
      if (isServerEmpty()) {
        clearLocal();
        return true;
      }
      if (isServerHashesEmpty()) {
        return true;
      }
      return false;
    } finally {
      m_rxBytes += counter.getByteCount();
      reader.close();
    }
  }
View Full Code Here

    Dimension size = null;
   
    FileInputStream fis=new FileInputStream(input);
    fis.skip(0x00019d91);
   
    CountingInputStream cin=new CountingInputStream(fis);
   
    ImageInputStream stream = ImageIO.createImageInputStream(cin);
    ImageReader reader = null;
    try {
      Iterator<?> iter = ImageIO.getImageReaders(stream);
      if (iter.hasNext()) {
        reader = (ImageReader) iter.next();
      } else {
        System.err.println("reader not found");
        reader = new DDSImageReaderSpi().createReaderInstance();
      }
     
      reader.setInput(stream, true, true);
      ImageReadParam param = reader.getDefaultReadParam();
     
      param.setSourceSubsampling(2, 2, 0, 0);
     
      if (mipmap == 0) {
        size = new Dimension(reader.getWidth(0), reader.getHeight(0));
        img = reader.read(0, param);
      } else {
        size = new Dimension(reader.getThumbnailWidth(0, mipmap - 1), reader.getThumbnailHeight(0, mipmap - 1));
        img = reader.readThumbnail(0, mipmap - 1);
      }
    } finally {
      if (reader != null) {
        reader.dispose();
      }
      stream.close();
    }
    //}
    if (img == null) {
      System.err.println("no image");
      return;
    }
    JFrame f = new JFrame();
    f.setResizable(false);
    ReaderTest comp = new ReaderTest(img);
    comp.setPreferredSize(size);
    f.add(comp);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.pack();
    f.setVisible(true);
   
    System.out.println(cin.getByteCount());
  }
View Full Code Here

         * @see DownloadJob
         */
        public File download(DownloadJob job, URL src) throws IOException {
            URLConnection con = connect(job,src);
            int total = con.getContentLength();
            CountingInputStream in = new CountingInputStream(con.getInputStream());
            byte[] buf = new byte[8192];
            int len;

            File dst = job.getDestination();
            File tmp = new File(dst.getPath()+".tmp");
            OutputStream out = new FileOutputStream(tmp);

            LOGGER.info("Downloading "+job.getName());
            try {
                while((len=in.read(buf))>=0) {
                    out.write(buf,0,len);
                    job.status = job.new Installing(total==-1 ? -1 : in.getCount()*100/total);
                }
            } catch (IOException e) {
                throw new IOException2("Failed to load "+src+" to "+tmp,e);
            }

            in.close();
            out.close();

            if (total!=-1 && total!=tmp.length()) {
                // don't know exactly how this happens, but report like
                // http://www.ashlux.com/wordpress/2009/08/14/hudson-and-the-sonar-plugin-fail-maveninstallation-nosuchmethoderror/
View Full Code Here

            if(listener!=null)
                listener.getLogger().println(message);

            InputStream in = con.getInputStream();
            CountingInputStream cis = new CountingInputStream(in);
            
            try {
                if(archive.toExternalForm().endsWith(".zip"))
                    unzipFrom(cis);
            else
                untarFrom(cis,GZIP);
            } catch (IOException e) {
                throw new IOException2(String.format("Failed to unpack %s (%d bytes read of total %d)",
                        archive,cis.getByteCount(),con.getContentLength()),e);
            }
            timestamp.touch(sourceTimestamp);
            return true;
        } catch (IOException e) {
            throw new IOException2("Failed to install "+archive+" to "+remote,e);
View Full Code Here

TOP

Related Classes of org.apache.commons.io.input.CountingInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.