private void fileInitialization(String[] filenames, File targetFile)
throws IOException {
if (files.length == 1) {
long length = torrent.getLengths()[0];
files[0] = new DataFile(targetFile, length);
int[] pieces = new int[torrent.getPieces().length];
for (int i = 0; i < pieces.length; i++) {
pieces[i] = i;
}
files[0].setPieces(pieces, pieceLength, pieceLength);
remaining = length;
} else {
int count = 0;
int piece = 0;
int currentLength = pieceLength;
for (int i = 0; i < filenames.length; i++) {
File file = new File(targetFile + File.separator + filenames[i]);
if (!file.getParentFile().exists()
&& !file.getParentFile().mkdirs()) {
throw new IOException("The folders needed by this torrent could not be created"); //$NON-NLS-1$
}
long fileLength = torrent.getLengths()[i];
files[i] = new DataFile(file, fileLength);
if (currentLength > fileLength) {
files[i].setPieces(new int[] { count }, (int) fileLength,
(int) fileLength);
currentLength -= fileLength;