List of usage examples for org.apache.commons.io.input SwappedDataInputStream SwappedDataInputStream
public SwappedDataInputStream(InputStream input)
From source file:odcplot.OdcPlot.java
/** * For binary input files from our frame reader set up the input stream * @return number of entries to read//from w w w .j a v a 2 s . co m * @throws WebUtilException */ private long setupFileReads() throws WebUtilException { setProgress("Scan input file for min/max GPS times."); File inFile = new File(infilename); long siz = inFile.length() / (Float.SIZE / 8) / 2; // convert bytes to # entries (time, val) if (!inFile.canRead()) { throw new WebUtilException("Can't open " + infilename + " for reading"); } try { inStream = new SwappedDataInputStream(new FileInputStream(inFile)); float minTime = Float.MAX_VALUE; float maxTime = -Float.MAX_VALUE; setProgress("Searhing for min/max time in input file."); int opct = 0; for (int i = 0; i < siz; i++) { int pct = (int) (100 * i / siz); if (pct > opct) { setProgress(pct, 100); opct = pct; } Float t = inStream.readFloat(); Float d = inStream.readFloat(); minTime = Math.min(minTime, t); maxTime = Math.max(maxTime, t); } startGPS = (int) (minTime * 24 * 3600); duration = (int) ((maxTime - minTime) * 24 * 3600); inStream.close(); inStream = new SwappedDataInputStream(new FileInputStream(inFile)); } catch (IOException ex) { throw new WebUtilException("Can't open " + infilename + " for reading"); } return siz; }
From source file:spectrogram.Spectrogram.java
private void readAddRawData() throws WebUtilException, NDSException { if (rawDataFilename != null && !rawDataFilename.isEmpty()) { rawDataFile = new File(rawDataFilename); }//from www . j a v a 2 s.co m if (rawDataFile == null || !rawDataFile.canRead()) { throw new WebUtilException("Request for raw data but file cannot be read, or not set."); } long nSamples = rawDataFile.length() / (Float.SIZE / 8) / 2; try { inStream = new SwappedDataInputStream(new FileInputStream(rawDataFile)); int startPos = 0; int blen = (int) Math.min(nSamples, 1024 * 1024); double[] rawDataBuffer = new double[blen]; for (long n = 0; n < nSamples; n += blen) { int dlen = blen; if (n + blen > nSamples) { dlen = (int) (nSamples - n); } for (int i = 0; i < dlen; i++) { Float t = inStream.readFloat(); Float d = inStream.readFloat(); rawDataBuffer[i] = d; } addBuf(rawDataBuffer, (int) n, dlen); } } catch (IOException ex) { throw new WebUtilException("Error reading raw data file", ex); } }
From source file:spectrogram.Spectrogram.java
/** * For binary input files from our frame reader set up the input stream * * @return number of entries to read/* www . j a v a 2 s . co m*/ * @throws WebUtilException */ private long setupFileReads(String infilename) throws WebUtilException { setProgress("Scan input file for min/max GPS times."); File inFile = new File(infilename); long siz = inFile.length() / (Float.SIZE / 8) / 2; // convert bytes to # entries (time, val) if (!inFile.canRead()) { throw new WebUtilException("Can't open " + infilename + " for reading"); } try { inStream = new SwappedDataInputStream(new FileInputStream(inFile)); float minTime = Float.MAX_VALUE; float maxTime = -Float.MAX_VALUE; setProgress("Searhing for min/max time in input file."); int opct = 0; for (int i = 0; i < siz; i++) { int pct = (int) (100 * i / siz); if (pct > opct) { setProgress(pct, 100); opct = pct; } Float t = inStream.readFloat(); Float d = inStream.readFloat(); minTime = Math.min(minTime, t); maxTime = Math.max(maxTime, t); } startGPS = (int) (minTime); duration = (int) (maxTime - minTime); inStream.close(); inStream = new SwappedDataInputStream(new FileInputStream(inFile)); } catch (IOException ex) { throw new WebUtilException("Can't open " + infilename + " for reading"); } return siz; }