org.alliance.core.file.blockstorage
Class BlockFile

java.lang.Object
  extended by org.alliance.core.file.blockstorage.BlockFile

public final class BlockFile
extends java.lang.Object

Contains information about an incomplete file. What block is has (and in what order) and what the FileDescriptor is for this file. Created by IntelliJ IDEA. User: maciek Date: 2006-jan-20 Time: 13:04:46


Constructor Summary
BlockFile(FileDescriptor fd, BlockStorage parent)
           
 
Method Summary
 void assureOpen()
           
 void blockCompleted(int blockNumber)
           
 Hash calculateHash(int blockNumber)
           
 void close()
           
static BlockFile createFrom(BlockStorage parent, java.io.InputStream is)
           
 BlockMask getBlockMask()
           
 java.util.BitSet getBlocksInProgress()
           
 int getBlockSize(int blockNumber)
           
static int getBlockSize(int blockNumber, long size)
           
 FileDescriptor getFd()
           
 int getHighestCompleteBlock()
           
static int getNumberOfBlockForSize(long size)
           
 int getNumberOfBlocksComplete()
           
 int getNumberOfBlocksStartedOrComplete()
           
 boolean isBlockComplete(int blockNumber)
           
 boolean isBlockStartedOrComplete(int blockNumber)
           
 boolean isComplete()
           
 boolean isOpen()
           
static BlockFile loadFrom(BlockStorage parent, Hash root)
           
 void moveToComplete(java.lang.String directory)
           
 void open()
           
 int read(int blockNumber, int sliceOffset, java.nio.ByteBuffer buf)
           
 void save()
           
 void serializeTo(java.io.OutputStream o)
           
 java.lang.String toString()
           
 int write(int blockNumber, int sliceOffset, java.nio.ByteBuffer slice)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BlockFile

public BlockFile(FileDescriptor fd,
                 BlockStorage parent)
Method Detail

getNumberOfBlockForSize

public static int getNumberOfBlockForSize(long size)

blockCompleted

public void blockCompleted(int blockNumber)

isBlockComplete

public boolean isBlockComplete(int blockNumber)

getBlocksInProgress

public java.util.BitSet getBlocksInProgress()

getNumberOfBlocksStartedOrComplete

public int getNumberOfBlocksStartedOrComplete()

getNumberOfBlocksComplete

public int getNumberOfBlocksComplete()

isBlockStartedOrComplete

public boolean isBlockStartedOrComplete(int blockNumber)

isComplete

public boolean isComplete()

serializeTo

public void serializeTo(java.io.OutputStream o)
                 throws java.io.IOException
Throws:
java.io.IOException

createFrom

public static BlockFile createFrom(BlockStorage parent,
                                   java.io.InputStream is)
                            throws java.io.IOException
Throws:
java.io.IOException

save

public void save()
          throws java.io.IOException
Throws:
java.io.IOException

loadFrom

public static BlockFile loadFrom(BlockStorage parent,
                                 Hash root)
                          throws java.io.IOException
Throws:
java.io.IOException

getFd

public FileDescriptor getFd()

isOpen

public boolean isOpen()

open

public void open()
          throws java.io.IOException
Throws:
java.io.IOException

assureOpen

public void assureOpen()
                throws java.io.IOException
Throws:
java.io.IOException

write

public int write(int blockNumber,
                 int sliceOffset,
                 java.nio.ByteBuffer slice)
          throws java.io.IOException
Returns:
Number of bytes written, or -1 if the block is complete
Throws:
java.io.IOException

read

public int read(int blockNumber,
                int sliceOffset,
                java.nio.ByteBuffer buf)
         throws java.io.IOException
Throws:
java.io.IOException

calculateHash

public Hash calculateHash(int blockNumber)
                   throws java.io.IOException
Throws:
java.io.IOException

getBlockSize

public int getBlockSize(int blockNumber)

getBlockSize

public static int getBlockSize(int blockNumber,
                               long size)

moveToComplete

public void moveToComplete(java.lang.String directory)
                    throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

getBlockMask

public BlockMask getBlockMask()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getHighestCompleteBlock

public int getHighestCompleteBlock()