|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.klomp.snark.Storage
public class Storage
Maintains pieces on disk. Can be used to store and retrieve pieces.
Field Summary | |
---|---|
static int |
MAX_PIECE_SIZE
note that we start reducing max number of peer connections above 1MB |
static int |
MAX_PIECES
The maximum number of pieces in a torrent. |
static long |
MAX_TOTAL_SIZE
|
Constructor Summary | |
---|---|
Storage(I2PSnarkUtil util,
File baseFile,
String announce,
boolean privateTorrent,
StorageListener listener)
Creates a storage from the existing file or directory. |
|
Storage(I2PSnarkUtil util,
MetaInfo metainfo,
StorageListener listener)
Creates a new storage based on the supplied MetaInfo. |
Method Summary | |
---|---|
void |
check(String rootDir)
Creates (and/or checks) all files from the metainfo file list. |
void |
check(String rootDir,
long savedTime,
BitField savedBitField)
use a saved bitfield and timestamp from a config file |
void |
cleanRAFs()
|
void |
close()
Closes the Storage and makes sure that all RandomAccessFiles are closed. |
boolean |
complete()
Whether or not this storage contains all pieces if the MetaInfo. |
static String |
filterName(String name)
Removes 'suspicious' characters from the given file name. |
String |
getBaseName()
The base file or directory name of the data, as specified in the .torrent file, but filtered to remove illegal characters. |
BitField |
getBitField()
The BitField that tells which pieces this storage contains. |
static File |
getFileFromNames(File base,
List<String> names)
|
int[] |
getFilePriorities()
Get the file priorities array. |
MetaInfo |
getMetaInfo()
Returns the MetaInfo associated with this Storage. |
ByteArray |
getPiece(int piece,
int off,
int len)
Returns a byte array containing a portion of the requested piece or null if the storage doesn't contain the piece yet. |
int[] |
getPiecePriorities()
Call setPriority() for all changed files first, then call this. |
int |
getPriority(String file)
|
boolean |
isAllocating()
Disk allocation (ballooning) in progress. |
boolean |
isChanged()
Has the storage changed since instantiation? |
boolean |
isChecking()
File checking in progress. |
static void |
main(String[] args)
Create a metainfo. |
int |
needed()
How many pieces are still missing from this storage. |
boolean |
putPiece(PartialPiece pp)
Put the piece in the Storage if it is correct. |
long |
remaining(String file)
|
void |
reopen(String rootDir)
Doesn't really reopen the file descriptors for a restart. |
(package private) void |
setFilePriorities(int[] p)
Set the file priorities array. |
void |
setPriority(String file,
int pri)
Must call Snark.updatePiecePriorities() (which calls getPiecePriorities()) after calling this. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_PIECE_SIZE
public static final int MAX_PIECES
public static final long MAX_TOTAL_SIZE
Constructor Detail |
---|
public Storage(I2PSnarkUtil util, MetaInfo metainfo, StorageListener listener)
public Storage(I2PSnarkUtil util, File baseFile, String announce, boolean privateTorrent, StorageListener listener) throws IOException
announce
- may be nulllistener
- may be null
IOException
- when creating and/or checking files fails.Method Detail |
---|
public MetaInfo getMetaInfo()
public int needed()
public boolean complete()
public boolean isChanged()
public boolean isChecking()
public boolean isAllocating()
public long remaining(String file)
file
- canonical path (non-directory)
public int getPriority(String file)
file
- canonical path (non-directory)public void setPriority(String file, int pri)
file
- canonical path (non-directory)pri
- default 0; <0 to disablepublic int[] getFilePriorities()
void setFilePriorities(int[] p)
p
- may be nullpublic int[] getPiecePriorities()
public BitField getBitField()
public String getBaseName()
public void check(String rootDir) throws IOException
IOException
public void check(String rootDir, long savedTime, BitField savedBitField) throws IOException
IOException
public void reopen(String rootDir) throws IOException
rootDir
- ignored
IOE
- on fail
IOException
public static String filterName(String name)
public static File getFileFromNames(File base, List<String> names)
public void close() throws IOException
IOException
public ByteArray getPiece(int piece, int off, int len) throws IOException
IOException
public boolean putPiece(PartialPiece pp) throws IOException
IOException
- when some storage related error occurs.public void cleanRAFs()
public static void main(String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |