public final void close() throws IOException { dataSource.close(); } }
/** Constructor for a RandomDataInput object */ public BitFileBuffered(RandomDataInput f) { file = f; buffer_size = DEFAULT_BUFFER_LENGTH; try{ fileSize = f.length(); } catch (IOException ioe) { logger.error("Input/Output exception getting file length in BitFileBuffered object.", ioe); } }
/** * {@inheritDoc} */ public V get(int entryNumber) { try{ if (entryNumber > numberOfEntries) throw new NoSuchElementException(); dataFile.seek((long)entryNumber * entrySize); value.readFields(dataFile); return value; } catch (Exception e) { throw new NoSuchElementException(e.getMessage()); } } }
public BufferedFileByteIn(RandomDataInput file, int bufferSize, long startByteOffset, ByteFileBuffered father) throws IOException { this.file = file; this.father = father; try { file.seek(startByteOffset); this.di = new BufferedDataInput(file, file.length() - startByteOffset, bufferSize); this.byteOffset = startByteOffset; } catch (IOException e) { logger.error( "Input/Output exception while reading from a random access file. Stack trace follows", e); } } }
protected void doTest(RandomDataInput rdi) throws IOException { //System.err.println("As stream"); for(byte b : data) { byte got = rdi.readByte(); System.err.println("Got=" + got + " expected " + b); assertEquals(b, got); } rdi.seek(0); for(byte b : data) { byte got = rdi.readByte(); //System.err.println("Got=" + got + " expected " + b); assertEquals(b, got); } for(int i=0;i<data.length;i++) { rdi.seek(i); byte got = rdi.readByte(); //System.err.println("Got=" + got + " expected " + data[i]); assertEquals(data[i], got); } } }
/** * {@inheritDoc} */ public V get(int entryNumber) { try{ if (entryNumber > numberOfEntries) throw new NoSuchElementException(); dataFile.seek((long)entryNumber * entrySize); value.readFields(dataFile); return value; } catch (Exception e) { throw new NoSuchElementException(e.getMessage()); } } }
public BufferedFileByteIn(RandomDataInput file, int bufferSize, long startByteOffset, ByteFileBuffered father) throws IOException { this.file = file; this.father = father; try { file.seek(startByteOffset); this.di = new BufferedDataInput(file, file.length() - startByteOffset, bufferSize); this.byteOffset = startByteOffset; } catch (IOException e) { logger.error( "Input/Output exception while reading from a random access file. Stack trace follows", e); } } }
@Override public V get(int entryNumber) { try{ V value = valueFactory.newInstance(); if (entryNumber > numberOfEntries) throw new NoSuchElementException("Entry too big : " + entryNumber + " > " + numberOfEntries); dataFile.seek((long)entryNumber * entrySize); value.readFields(dataFile); return value; } catch (NoSuchElementException nsee) { throw nsee; } catch (Exception e) { throw new NoSuchElementException("For entry number "+entryNumber +" : " + e); } }
public void close() throws IOException { lexIdFile.close(); } }
/** Constructor for a RandomDataInput object */ public BitFileBuffered(RandomDataInput f) { file = f; buffer_size = DEFAULT_BUFFER_LENGTH; try{ fileSize = f.length(); } catch (IOException ioe) { logger.error("Input/Output exception getting file length in BitFileBuffered object.", ioe); } }
@Override public void skipBytes(long len) throws IOException { if (readByteOffset + len >= inBuffer.length) { offset += len; synchronized (parentFile) { parentFile.seek(offset); // we skip the first bytes of the next block readByteOffset = 0; try{ parentFile.readFully(inBuffer); } catch (EOFException eofe) { /* ignore this */} } byteRead = inBuffer[readByteOffset]; } else { offset += len; readByteOffset += len; bitOffset = 0; byteRead = inBuffer[readByteOffset]; } } }
@Override public V get(int entryNumber) { try{ V value = valueFactory.newInstance(); if (entryNumber > numberOfEntries) throw new NoSuchElementException("Entry too big : " + entryNumber + " > " + numberOfEntries); dataFile.seek((long)entryNumber * entrySize); value.readFields(dataFile); return value; } catch (NoSuchElementException nsee) { throw nsee; } catch (Exception e) { throw new NoSuchElementException("For entry number "+entryNumber +" : " + e); } }
public final void close() throws IOException { dataSource.close(); } }
/** default constructor * * @param filename * @param updateable * @param _valueFactory * @throws IOException */ public FSArrayFile( String filename, boolean updateable, FixedSizeWriteableFactory<V> _valueFactory) throws IOException { this.dataFile = updateable ? Files.writeFileRandom(this.dataFilename = filename) : Files.openFileRandom(this.dataFilename = filename); this.valueFactory = _valueFactory; this.entrySize = _valueFactory.getSize(); this.numberOfEntries = (int) (dataFile.length() / (long)entrySize); }
@Override public void skipBytes(long len) throws IOException { if (readByteOffset + len >= inBuffer.length) { offset += len; synchronized (parentFile) { parentFile.seek(offset); // we skip the first bytes of the next block readByteOffset = 0; try{ parentFile.readFully(inBuffer); } catch (EOFException eofe) { /* ignore this */} } byteRead = inBuffer[readByteOffset]; } else { offset += len; readByteOffset += len; bitOffset = 0; byteRead = inBuffer[readByteOffset]; } } }
/** * {@inheritDoc} */ public Entry<K,V> get(int entryNumber) { synchronized(fileAccessLock) { K key = keyFactory.newInstance(); V value = valueFactory.newInstance(); if (entryNumber >= numberOfEntries) throw new NoSuchElementException("Entry number "+ entryNumber + " is larger than map size of "+ numberOfEntries); try{ dataFile.seek((long)entryNumber * entrySize); key.readFields(dataFile); value.readFields(dataFile); } catch (IOException ioe) { throw new NoSuchElementException( "IOException reading FSOrderedMapFile for entry number "+ entryNumber +" : "+ioe); } return new MapFileEntry<K,V>(key, value, entryNumber); } } /**