java.io.Closeable
, java.lang.AutoCloseable
public class Storage
extends java.lang.Object
implements java.io.Closeable
修飾子とタイプ | フィールド | 説明 |
---|---|---|
static int |
MAX_PIECE_SIZE |
bigger than this will be rejected
|
static int |
MAX_PIECES |
The maximum number of pieces in a torrent.
|
static long |
MAX_TOTAL_SIZE |
コンストラクタ | 説明 |
---|---|
Storage(I2PSnarkUtil util,
java.io.File baseFile,
java.lang.String announce,
java.util.List<java.util.List<java.lang.String>> announce_list,
java.lang.String created_by,
boolean privateTorrent,
StorageListener listener) |
Creates a storage from the existing file or directory.
|
Storage(I2PSnarkUtil util,
java.io.File baseFile,
MetaInfo metainfo,
StorageListener listener,
boolean preserveFileNames) |
Creates a new storage based on the supplied MetaInfo.
|
修飾子とタイプ | メソッド | 説明 |
---|---|---|
void |
check() |
Creates (and/or checks) all files from the metainfo file list.
|
void |
check(long savedTime,
BitField savedBitField) |
Creates (and/or checks) all files from the metainfo file list.
|
void |
cleanRAFs() |
Close unused RAFs - call periodically
|
(package private) void |
clearChanged() |
Clear the storage changed variable
|
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 java.lang.String |
filterName(java.lang.String name) |
Removes 'suspicious' characters from the given file name.
|
java.io.File |
getBase() |
The base file or directory.
|
java.lang.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.
|
double |
getCheckingProgress() |
If checking is in progress, return completion 0.0 ...
|
java.util.SortedSet<java.io.File> |
getDirectories() |
Includes the base for a multi-file torrent.
|
int |
getFileCount() |
Does not include directories.
|
int[] |
getFilePriorities() |
Get the file priorities array.
|
java.util.List<java.io.File> |
getFiles() |
Does not include directories.
|
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.
|
boolean |
getPreserveFileNames() |
|
int |
getPriority(int fileIndex) |
|
long |
getSkippedLength() |
Call setPriority() for all changed files first,
then call this.
|
int |
indexOf(java.io.File file) |
Get index to pass to remaining(), getPriority(), setPriority()
|
boolean |
isAllocating() |
Disk allocation (ballooning) in progress.
|
boolean |
isChanged() |
Has the storage changed since instantiation?
|
boolean |
isChecking() |
File checking in progress.
|
static void |
main(java.lang.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.
|
boolean |
recheck() |
Blocking.
|
long[] |
remaining() |
For efficiency, calculate remaining bytes for all files at once
|
void |
reopen() |
Doesn't really reopen the file descriptors for a restart.
|
(package private) void |
setFilePriorities(int[] p) |
Set the file priorities array.
|
void |
setPriority(int fileIndex,
int pri) |
Must call Snark.updatePiecePriorities()
(which calls getPiecePriorities()) after calling this.
|
public static final int MAX_PIECE_SIZE
public static final int MAX_PIECES
public static final long MAX_TOTAL_SIZE
public Storage(I2PSnarkUtil util, java.io.File baseFile, MetaInfo metainfo, StorageListener listener, boolean preserveFileNames)
baseFile
- the torrent data file or dirpreserveFileNames
- if true, do not remap names to a 'safe' charsetpublic Storage(I2PSnarkUtil util, java.io.File baseFile, java.lang.String announce, java.util.List<java.util.List<java.lang.String>> announce_list, java.lang.String created_by, boolean privateTorrent, StorageListener listener) throws java.io.IOException
announce
- may be nulllistener
- may be nullcreated_by
- may be nulljava.io.IOException
- when creating and/or checking files fails.public MetaInfo getMetaInfo()
public int needed()
public boolean complete()
public boolean isChanged()
void clearChanged()
public boolean isChecking()
public double getCheckingProgress()
public boolean isAllocating()
public int indexOf(java.io.File file)
file
- non-canonical path (non-directory)public long[] remaining()
public int getPriority(int fileIndex)
fileIndex
- as obtained from indexOfpublic void setPriority(int fileIndex, int pri)
fileIndex
- as obtained from indexOfpri
- default 0; <0 to disablepublic int[] getFilePriorities()
void setFilePriorities(int[] p)
p
- may be nullpublic int[] getPiecePriorities()
public long getSkippedLength()
public BitField getBitField()
public java.lang.String getBaseName()
public boolean getPreserveFileNames()
public void check() throws java.io.IOException
java.lang.IllegalStateException
- if called more than oncejava.io.IOException
public void check(long savedTime, BitField savedBitField) throws java.io.IOException
java.lang.IllegalStateException
- if called more than oncejava.io.IOException
public void reopen() throws java.io.IOException
java.io.IOException
- on failpublic static java.lang.String filterName(java.lang.String name)
public java.io.File getBase()
public java.util.List<java.io.File> getFiles()
public int getFileCount()
public java.util.SortedSet<java.io.File> getDirectories()
public boolean recheck() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
インタフェース内 java.lang.AutoCloseable
close
インタフェース内 java.io.Closeable
java.io.IOException
public ByteArray getPiece(int piece, int off, int len) throws java.io.IOException
java.io.IOException
public boolean putPiece(PartialPiece pp) throws java.io.IOException
java.io.IOException
- when some storage related error occurs.public void cleanRAFs()
public static void main(java.lang.String[] args)