public final class FileStorage
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static file_flags_t |
FLAG_EXECUTABLE
This file is executable (sets the executable bit
on posix like systems).
|
static file_flags_t |
FLAG_HIDDEN
This file is hidden (sets the hidden attribute
on windows).
|
static file_flags_t |
FLAG_PAD_FILE
This file is a pad file.
|
static file_flags_t |
FLAG_SYMLINK
This file is a symlink.
|
| Constructor and Description |
|---|
FileStorage(file_storage fs) |
| Modifier and Type | Method and Description |
|---|---|
void |
addFile(java.lang.String p,
long size)
Adds a file to the file storage.
|
void |
addFile(java.lang.String path,
long size,
file_flags_t flags)
Adds a file to the file storage.
|
void |
addFile(java.lang.String path,
long size,
file_flags_t flags,
int mtime)
Adds a file to the file storage.
|
void |
addFile(java.lang.String path,
long size,
file_flags_t flags,
int mtime,
java.lang.String symlink)
Adds a file to the file storage.
|
boolean |
fileAbsolutePath(int index)
Returns true if the file at the specified index has been renamed to
have an absolute path, i.e.
|
file_flags_t |
fileFlags(int index)
Returns a bitmask of flags from
file_flags_t that apply
to file at index. |
int |
fileIndexAtOffset(long offset)
Returns the index of the file at the given offset in the torrent.
|
java.lang.String |
fileName(int index)
Returns only the name of the file, whereas
filePath(int) returns the path (inside the torrent file) with
the filename appended. |
long |
fileOffset(int index)
returns the byte offset within the torrent file
where this file starts.
|
java.lang.String |
filePath(int index)
Returns the full path to a file.
|
java.lang.String |
filePath(int index,
java.lang.String savePath)
returns the full path to a file.
|
long |
fileSize(int index)
returns the size of a file.
|
Sha1Hash |
hash(int index)
Is a sha-1 hash of the file, or 0 if none was
provided in the torrent file.
|
boolean |
isValid()
Returns true if the piece length has been initialized
on the file_storage.
|
java.util.ArrayList<FileSlice> |
mapBlock(int piece,
long offset,
int size)
Returns a list of
FileSlice objects representing the portions of
files the specified piece index, byte offset and size range overlaps. |
PeerRequest |
mapFile(int file,
long offset,
int size)
Returns a
PeerRequest representing the
piece index, byte offset and size the specified file range overlaps. |
java.lang.String |
name()
Get the name of this torrent.
|
void |
name(java.lang.String name)
Set the name of this torrent.
|
int |
numFiles()
Returns the number of files in the file_storage.
|
int |
numPieces()
Returns the number of pieces in the torrent.
|
void |
numPieces(int n)
Set the number of pieces in the torrent.
|
boolean |
padFileAt(int index)
returns true if the file at the given
index is a pad-file.
|
java.util.ArrayList<java.lang.String> |
paths() |
int |
pieceLength()
Get the size of each piece in this torrent.
|
void |
pieceLength(int l)
Set the size of each piece in this torrent.
|
int |
pieceSize(int index)
Returns the piece size of
index. |
void |
renameFile(int index,
java.lang.String newFilename)
Renames the file at
index to newFilename. |
void |
reserve(int numFiles)
Allocates space for
numFiles in the internal file list. |
file_storage |
swig() |
torrent_info |
ti()
This methods returns the internal torrent info or null
if it was constructed without one.
|
long |
totalSize()
Returns the total number of bytes all the files in this torrent spans.
|
public static final file_flags_t FLAG_PAD_FILE
public static final file_flags_t FLAG_HIDDEN
public static final file_flags_t FLAG_EXECUTABLE
public static final file_flags_t FLAG_SYMLINK
public FileStorage(file_storage fs)
fs - the native objectpublic file_storage swig()
public torrent_info ti()
This also prevent premature garbage collection in case the storage was created from a torrent info.
public boolean isValid()
public void reserve(int numFiles)
numFiles in the internal file list. This can
be used to avoid reallocating the internal file list when the number
of files to be added is known up-front.numFiles - the number of filespublic void addFile(java.lang.String path,
long size,
file_flags_t flags,
int mtime,
java.lang.String symlink)
flags argument sets attributes on the file.
The file attributes is an extension and may not work in all bittorrent clients.
If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same.
This shared path element is also set to the name of the torrent. It
can be changed by calling name(String).
The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
path - the pathsize - the file sizeflags - the file flagsmtime - the timesymlink - the symlinkpublic void addFile(java.lang.String path,
long size,
file_flags_t flags,
int mtime)
flags argument sets attributes on the file.
The file attributes is an extension and may not work in all bittorrent clients.
If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same.
This shared path element is also set to the name of the torrent. It
can be changed by calling name(String).
The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
path - the pathsize - the file sizeflags - the file flagsmtime - the timepublic void addFile(java.lang.String path,
long size,
file_flags_t flags)
flags argument sets attributes on the file.
The file attributes is an extension and may not work in all bittorrent clients.
If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same.
This shared path element is also set to the name of the torrent. It
can be changed by calling name(String).
The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
path - the pathsize - the file sizeflags - the file flagspublic void addFile(java.lang.String p,
long size)
If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same.
This shared path element is also set to the name of the torrent. It
can be changed by calling name(String).
The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
p - size - public void renameFile(int index,
java.lang.String newFilename)
index to newFilename. Keep in mind
that filenames are expected to be UTF-8 encoded.index - newFilename - public java.util.ArrayList<FileSlice> mapBlock(int piece, long offset, int size)
FileSlice objects representing the portions of
files the specified piece index, byte offset and size range overlaps.
This is the inverse mapping of mapFile(int, long, int).
piece - offset - size - public PeerRequest mapFile(int file, long offset, int size)
PeerRequest representing the
piece index, byte offset and size the specified file range overlaps.
This is the inverse mapping of mapBlock(int, long, int).
Note that the PeerRequest return type
is meant to hold bittorrent block requests, which may not be larger
than 16 kiB. Mapping a range larger than that may return an overflown
integer.
file - offset - size - public int numFiles()
public long totalSize()
public int numPieces()
public void numPieces(int n)
n - public int pieceLength()
public void pieceLength(int l)
l - public int pieceSize(int index)
index. This will be the same as pieceLength(),
except for the last piece, which may be shorter.index - public java.lang.String name()
public void name(java.lang.String name)
name - public Sha1Hash hash(int index)
index - public java.lang.String filePath(int index,
java.lang.String savePath)
index - savePath - public java.lang.String filePath(int index)
index - the file indexpublic java.lang.String fileName(int index)
filePath(int) returns the path (inside the torrent file) with
the filename appended.index - the file indexpublic long fileSize(int index)
index - public boolean padFileAt(int index)
index - public long fileOffset(int index)
index - public java.util.ArrayList<java.lang.String> paths()
public file_flags_t fileFlags(int index)
file_flags_t that apply
to file at index.index - public boolean fileAbsolutePath(int index)
index - public int fileIndexAtOffset(long offset)
offset -