List of usage examples for com.google.common.io LittleEndianDataInputStream close
public void close() throws IOException
From source file:net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.XcaliburRawFileReadTask.java
/** * This method reads the dump of the RAW data file produced by RAWdump.exe * utility (see RAWdump.cpp source for details). */// w w w .j av a 2s . co m private void readRAWDump(InputStream dumpStream) throws IOException { String line; while ((line = TextUtils.readLineFromStream(dumpStream)) != null) { if (isCanceled()) { return; } if (line.startsWith("ERROR: ")) { throw (new IOException(line.substring("ERROR: ".length()))); } if (line.startsWith("NUMBER OF SCANS: ")) { totalScans = Integer.parseInt(line.substring("NUMBER OF SCANS: ".length())); } if (line.startsWith("SCAN NUMBER: ")) { scanNumber = Integer.parseInt(line.substring("SCAN NUMBER: ".length())); } if (line.startsWith("SCAN FILTER: ")) { /* * A typical filter line for MS/MS scan looks like this: * * ITMS - c ESI d Full ms3 587.03@cid35.00 323.00@cid35.00 */ Pattern p = Pattern.compile("ms(\\d).* (\\d+\\.\\d+)@"); Matcher m = p.matcher(line); if (m.find()) { msLevel = Integer.parseInt(m.group(1)); // Initially we obtain precursor m/z from this filter line, // even though the precision is not good. Later more precise // precursor m/z may be reported using PRECURSOR: line, but // sometimes it is missing (equal to 0) precursorMZ = Double.parseDouble(m.group(2)); } else { msLevel = 1; } } if (line.startsWith("RETENTION TIME: ")) { // Retention time in the RAW file is reported in minutes. retentionTime = Double.parseDouble(line.substring("RETENTION TIME: ".length())); } if (line.startsWith("PRECURSOR: ")) { String tokens[] = line.split(" "); double token2 = Double.parseDouble(tokens[1]); int token3 = Integer.parseInt(tokens[2]); if (token2 > 0) { precursorMZ = token2; precursorCharge = token3; } } if (line.startsWith("DATA POINTS: ")) { int numOfDataPoints = Integer.parseInt(line.substring("DATA POINTS: ".length())); DataPoint completeDataPoints[] = new DataPoint[numOfDataPoints]; // Because Intel CPU is using little endian natively, we // need to use LittleEndianDataInputStream instead of normal // Java DataInputStream, which is big-endian. LittleEndianDataInputStream dis = new LittleEndianDataInputStream(dumpStream); for (int i = 0; i < numOfDataPoints; i++) { double mz = dis.readDouble(); double intensity = dis.readDouble(); completeDataPoints[i] = new SimpleDataPoint(mz, intensity); } dis.close(); boolean centroided = ScanUtils.isCentroided(completeDataPoints); DataPoint optimizedDataPoints[] = ScanUtils.removeZeroDataPoints(completeDataPoints, centroided); /* * If this scan is a full scan (ms level = 1), it means that the * previous scans stored in the stack, are complete and ready to * be written to the raw data file. */ if (msLevel == 1) { while (!parentStack.isEmpty()) { SimpleScan currentScan = parentStack.removeFirst(); newMZmineFile.addScan(currentScan); } } // Setting the current parentScan int parentScan = -1; if (msLevel > 1) { parentScan = parentTreeValue[msLevel - 1]; if (!parentStack.isEmpty()) { for (SimpleScan s : parentStack) { if (s.getScanNumber() == parentScan) { s.addFragmentScan(scanNumber); } } } } // Setting the parent scan number for this level of fragments parentTreeValue[msLevel] = scanNumber; SimpleScan newScan = new SimpleScan(null, scanNumber, msLevel, retentionTime, parentScan, precursorMZ, precursorCharge, null, optimizedDataPoints, centroided); parentStack.add(newScan); parsedScans++; // Clean the variables for next scan scanNumber = 0; msLevel = 0; retentionTime = 0; precursorMZ = 0; precursorCharge = 0; } } // Add remaining scans in the parentStack while (!parentStack.isEmpty()) { SimpleScan currentScan = parentStack.removeFirst(); newMZmineFile.addScan(currentScan); } }
From source file:org.esa.nest.gpf.ReadRatFileOp.java
/** * Called by the framework in order to compute a tile for the given target band. * <p>The default implementation throws a runtime exception with the message "not implemented".</p> * * @param targetTileMap The target tiles associated with all target bands to be computed. * @param targetRectangle The rectangle of target tile. * @param pm A progress monitor which should be used to determine computation cancelation requests. * @throws org.esa.beam.framework.gpf.OperatorException * If an error occurs during computation of the target raster. *///from w ww .java2 s. c o m @Override public synchronized void computeTileStack(Map<Band, Tile> targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorException { final int x0 = targetRectangle.x; final int y0 = targetRectangle.y; final int w = targetRectangle.width; final int h = targetRectangle.height; final int xMax = x0 + w; final int yMax = y0 + h; //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h); final Band tgtBandI = targetProduct.getBand("i_band"); final Band tgtBandQ = targetProduct.getBand("q_band"); final Tile tgtTileI = targetTileMap.get(tgtBandI); final Tile tgtTileQ = targetTileMap.get(tgtBandQ); final ProductData tgtBufferI = tgtTileI.getDataBuffer(); final ProductData tgtBufferQ = tgtTileQ.getDataBuffer(); final TileIndex tgtIndex = new TileIndex(tgtTileI); try { LittleEndianDataInputStream in = new LittleEndianDataInputStream( new BufferedInputStream(new FileInputStream(ratFilePath))); in.skipBytes(1000 + y0 * width * 4 * 2); for (int y = y0; y < yMax; y++) { tgtIndex.calculateStride(y); for (int x = x0; x < xMax; x++) { final int tgtIdx = tgtIndex.getIndex(x); final float vI = in.readFloat(); final float vQ = in.readFloat(); tgtBufferI.setElemDoubleAt(tgtIdx, vI); tgtBufferQ.setElemDoubleAt(tgtIdx, vQ); } } in.close(); } catch (Throwable e) { OperatorUtils.catchOperatorException("computeTileStack", e); } }