public synchronized TDFGroup getGroup(String name) { if (groupCache.containsKey(name)) { return groupCache.get(name); } try { IndexEntry ie = groupIndex.get(name); long position = ie.position; int nBytes = ie.nBytes; //fis.seek(position); //byte[] buffer = new byte[nBytes]; //readFully(buffer); byte[] buffer = readBytes(position, nBytes); ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); TDFGroup group = new TDFGroup(name, byteBuffer); groupCache.put(name, group); return group; } catch (IOException ex) { log.error("Error reading group: " + name, ex); throw new RuntimeException("System error occured while reading group: " + name); } }
byte[] bytes = readBytes(idxPosition, nBytes); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
public synchronized TDFGroup getGroup(String name) { if (groupCache.containsKey(name)) { return groupCache.get(name); } try { IndexEntry ie = groupIndex.get(name); long position = ie.position; int nBytes = ie.nBytes; //fis.seek(position); //byte[] buffer = new byte[nBytes]; //readFully(buffer); byte[] buffer = readBytes(position, nBytes); ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); TDFGroup group = new TDFGroup(name, byteBuffer); groupCache.put(name, group); return group; } catch (IOException ex) { log.error("Error reading group: " + name, ex); throw new RuntimeException("System error occured while reading group: " + name); } }
public synchronized TDFDataset getDataset(String name) { if (datasetCache.containsKey(name)) { return datasetCache.get(name); } try { if (datasetIndex.containsKey(name)) { IndexEntry ie = datasetIndex.get(name); long position = ie.position; int nBytes = ie.nBytes; //fis.seek(position); //byte[] buffer = new byte[nBytes]; //readFully(buffer); byte[] buffer = readBytes(position, nBytes); ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); TDFDataset ds = new TDFDataset(name, byteBuffer, this); datasetCache.put(name, ds); return ds; } else { return null; } } catch (IOException ex) { log.error("Error reading dataset: " + name, ex); throw new RuntimeException("System error occured while reading dataset: " + name); } }
private void readMasterIndex(long idxPosition, int nBytes) throws IOException { try { //fis.seek(idxPosition); //byte[] bytes = new byte[nBytes]; //readFully(bytes); byte[] bytes = readBytes(idxPosition, nBytes); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); int nDatasets = byteBuffer.getInt(); datasetIndex = new LinkedHashMap(nDatasets); for (int i = 0; i < nDatasets; i++) { String name = StringUtils.readString(byteBuffer); long fPosition = byteBuffer.getLong(); int n = byteBuffer.getInt(); datasetIndex.put(name, new IndexEntry(fPosition, n)); } int nGroups = byteBuffer.getInt(); groupIndex = new LinkedHashMap(nGroups); for (int i = 0; i < nGroups; i++) { String name = StringUtils.readString(byteBuffer); long fPosition = byteBuffer.getLong(); int n = byteBuffer.getInt(); groupIndex.put(name, new IndexEntry(fPosition, n)); } } catch (BufferUnderflowException e) { // We intermittently see this exception in this method. Log as much info as possible log.error("BufferUnderflowException. path=" + getPath() + " idxPosition=" + idxPosition + " nBytes=" + nBytes); throw e; } }
public TDFTile readTile(TDFDataset ds, int tileNumber) { try { if (tileNumber >= ds.tilePositions.length) { // TODO - return empty tile return null; } long position = ds.tilePositions[tileNumber]; if (position < 0) { // Indicates empty tile // TODO -- return an empty tile? return null; } int nBytes = ds.tileSizes[tileNumber]; byte[] buffer = readBytes(position, nBytes); if (compressed) { buffer = CompressionUtils.decompress(buffer); } return TileFactory.createTile(buffer, trackNames.length); } catch (IOException ex) { String tileName = ds.getName() + "[" + tileNumber + "]"; log.error("Error reading data tile: " + tileName, ex); throw new RuntimeException("System error occured while reading tile: " + tileName); } }
public TDFTile readTile(TDFDataset ds, int tileNumber) { try { if (tileNumber >= ds.tilePositions.length) { // TODO - return empty tile return null; } long position = ds.tilePositions[tileNumber]; if (position < 0) { // Indicates empty tile // TODO -- return an empty tile? return null; } int nBytes = ds.tileSizes[tileNumber]; //fis.seek(position); //byte[] buffer = new byte[nBytes]; //readFully(buffer); byte[] buffer = readBytes(position, nBytes); if (compressed) { buffer = compressionUtils.decompress(buffer); } return TileFactory.createTile(buffer, trackNames.length); } catch (IOException ex) { String tileName = ds.getName() + "[" + tileNumber + "]"; log.error("Error reading data tile: " + tileName, ex); throw new RuntimeException("System error occured while reading tile: " + tileName); } }
public synchronized TDFDataset getDataset(String name) { if (datasetCache.containsKey(name)) { return datasetCache.get(name); } try { if (datasetIndex.containsKey(name)) { IndexEntry ie = datasetIndex.get(name); long position = ie.position; int nBytes = ie.nBytes; //fis.seek(position); //byte[] buffer = new byte[nBytes]; //readFully(buffer); byte[] buffer = readBytes(position, nBytes); ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); TDFDataset ds = new TDFDataset(name, byteBuffer, this); datasetCache.put(name, ds); return ds; } else { datasetCache.put(name, null); return null; } } catch (IOException ex) { log.error("Error reading dataset: " + getPath() + " (" + name + ")", ex); throw new RuntimeException("System error occured while reading dataset: " + name); } }