ListView list = (ListView) getActivity().findViewById(R.id.theIdOfTheList); (CustomArrayAdapter) caa = (CustomArrayAdapter) list.getAdapter(); File newFile = new File("directory" + "/test/theNewFileName.extension"); RecordFile rf = new RecordFile(); rf.setTitle(newFile.getName()); rf.setFileSize(readableFileSize(newFile.length())); // have a method to return a reference of the data list(or a method // to add the data directly in the adapter) List<RecordFile> data = caa.getListData(); data.add(rf); caa.notifyDataSetChanged();
/** * Commit all pending (in-memory) data by flushing the page manager. * This forces a flush of all outstanding blocks (this is an implicit * {@link RecordFile#commit} as well). */ void commit() throws IOException { // write the header out file.release( headerBuf ); file.commit(); // and obtain it again headerBuf = file.get( 0 ); header = new FileHeader( headerBuf, false ); }
/** * Switches off transactioning for the record manager. This means * that a) a transaction log is not kept, and b) writes aren't * synch'ed after every update. This is useful when batch inserting * into a new database. * <p> * Only call this method directly after opening the file, otherwise * the results will be undefined. */ public synchronized void disableTransactions() { checkIfClosed(); _physFile.disableTransactions(); _logicFile.disableTransactions(); _physFileFree.disableTransactions(); _logicFileFree.disableTransactions(); }
/** * Flushes the page manager. This forces a flush of all outstanding * blocks (this it's an implicit {@link RecordFile#commit} as well). */ void rollback() throws IOException { // release header file.discard(headerBuf); file.rollback(); // and obtain it again headerBuf = file.get(0); if (headerBuf.readShort(0) == 0) header = new FileHeader(headerBuf, true); else header = new FileHeader(headerBuf, false); }
/** Synchronizes the indicated blocks with the owner. */ private void synchronizeBlocks(Iterable<BlockIo> blocks, boolean fromCore) throws IOException { // write block vector elements to the data file. for(BlockIo cur:blocks){ owner.synch(cur); if (fromCore) { cur.decrementTransactionCount(); if (!cur.isInTransaction()) { owner.releaseFromTransaction(cur, true); } } } }
/** Synchronizes the indicated blocks with the owner. */ private void synchronizeBlocks(Iterator<BlockIo> blockIterator, boolean fromCore) throws IOException { // write block vector elements to the data file. while ( blockIterator.hasNext() ) { BlockIo cur = blockIterator.next(); owner.sync(cur); if (fromCore) { cur.decrementTransactionCount(); if (!cur.isInTransaction()) { owner.releaseFromTransaction(cur, true); } } } }
/** * Creates a record manager for the indicated file * * @throws IOException when the file cannot be opened or is not * a valid file content-wise. */ public BaseRecordManager( String filename ) throws IOException { recordFile = new RecordFile( filename ); pageMgr = new PageManager( recordFile ); physMgr = new PhysicalRowIdManager( pageMgr ); logMgr = new LogicalRowIdManager( pageMgr ); lockElements = new ConcurrentHashMap<Long, LockElement>(); }
node = getNewNode( blockid ); long offset = blockid * BLOCK_SIZE; if ( file.length() > 0 && offset <= file.length() ) read( file, offset, node.getData(), BLOCK_SIZE );
/** * Releases a block. * * @param blockId The record number to release. * @param isDirty If true, the block was modified since the get(). */ void release( long blockId, boolean isDirty ) throws IOException { BlockIo blockIo = inUse.get( blockId ); if ( blockIo == null ) { throw new IOException( I18n.err( I18n.ERR_555, blockId ) ); } if ( ! blockIo.isDirty() && isDirty ) { blockIo.setDirty(); } release( blockIo ); }
node = getNewNode(blockid); long offset = blockid * BLOCK_SIZE; FileChannel file = getChannel(offset); read(file, offset%MAX_FILE_SIZE, node.getData(), BLOCK_SIZE);
/** Discards the indicated blocks and notify the owner. */ private void discardBlocks(ArrayList blocks) throws IOException { for (Iterator k = blocks.iterator(); k.hasNext(); ) { BlockIo cur = (BlockIo) k.next(); cur.decrementTransactionCount(); if (!cur.isInTransaction()) { owner.releaseFromTransaction(cur, false); } } }
/** Builds logfile name */ private String makeLogName() { return owner.getFileName() + extension; }
/** * Closes the record manager. * * @throws IOException when one of the underlying I/O operations fails. */ public void close() throws IOException { checkIfClosed(); pageMgr.close(); pageMgr = null; recordFile.close(); recordFile = null; }
/** * Creates a new page manager using the indicated record recordFile. * We will load in memory the associated FileHeader, which is * read from the RecordFile if it exists, or is created if it doesn't. * * @param The associated RecordFile * @throws IOException If there is an issue storing data into the recordFile */ PageManager( RecordFile recordFile ) throws IOException { this.recordFile = recordFile; // Note that we hold on to the recordFile header node. headerBuf = recordFile.get( 0 ); // Assume recordFile is new if the recordFile header's magic number is 0. boolean isNew = headerBuf.readShort( 0 ) == 0; header = new FileHeader( headerBuf, isNew ); }
blockIo = getNewBlockIo( blockId ); long offset = blockId * BLOCK_SIZE; long fileLength = file.length(); read( file, offset, blockIo.getData(), BLOCK_SIZE );