use of com.biglybt.core.diskmanager.file.FMFileManagerException in project BiglyBT by BiglySoftware.
the class CacheFileWithoutCacheMT method read.
@Override
public void read(DirectByteBuffer[] buffers, long position, short policy) throws CacheFileManagerException {
int read_length = 0;
for (int i = 0; i < buffers.length; i++) {
read_length += buffers[i].remaining(DirectByteBuffer.SS_CACHE);
}
FMFile file = null;
try {
file = getFile();
file.read(buffers, position);
manager.fileBytesRead(read_length);
bytes_read += read_length;
} catch (FMFileManagerException e) {
manager.rethrow(this, e);
} finally {
releaseFile(file);
}
}
use of com.biglybt.core.diskmanager.file.FMFileManagerException in project BiglyBT by BiglySoftware.
the class CacheFileWithoutCacheMT method moveFile.
@Override
public void moveFile(File new_file, FileUtil.ProgressListener pl) throws CacheFileManagerException {
try {
synchronized (this) {
moving = true;
}
while (true) {
synchronized (this) {
boolean surviving = false;
for (int i = 1; i < files_use_count.length; i++) {
if (files_use_count[i] > 0) {
surviving = true;
break;
}
}
if (!surviving) {
for (int i = 1; i < files_use_count.length; i++) {
FMFile file = files[i];
if (file.isClone()) {
synchronized (CacheFileWithoutCacheMT.class) {
num_clones--;
}
}
file.close();
}
files = new FMFile[] { base_file };
files_use_count = new int[] { files_use_count[0] };
base_file.moveFile(new_file, pl);
break;
}
}
try {
System.out.println("CacheFileWithoutCacheMT: waiting for clones to die");
Thread.sleep(250);
} catch (Throwable e) {
}
}
} catch (FMFileManagerException e) {
manager.rethrow(this, e);
} finally {
synchronized (this) {
moving = false;
}
}
}
use of com.biglybt.core.diskmanager.file.FMFileManagerException in project BiglyBT by BiglySoftware.
the class FMFileAccessLinear method read.
public void read(FileAccessor fa, DirectByteBuffer buffer, long offset) throws FMFileManagerException {
if (fa == null) {
throw new FMFileManagerException("read: fa is null");
}
FileChannel fc = fa.getChannel();
if (!fc.isOpen()) {
Debug.out("FileChannel is closed: " + owner.getName());
throw (new FMFileManagerException("read - file is closed"));
}
AEThread2.setDebug(owner);
try {
if (USE_MMAP) {
long remainingInFile = fc.size() - offset;
long remainingInTargetBuffer = buffer.remaining(DirectByteBuffer.SS_FILE);
MappedByteBuffer buf = fc.map(MapMode.READ_ONLY, offset, Math.min(remainingInFile, remainingInTargetBuffer));
buffer.put(DirectByteBuffer.SS_FILE, buf);
} else {
fc.position(offset);
while (fc.position() < fc.size() && buffer.hasRemaining(DirectByteBuffer.SS_FILE)) buffer.read(DirectByteBuffer.SS_FILE, fc);
}
} catch (Exception e) {
Debug.printStackTrace(e);
throw (new FMFileManagerException("read fails", e));
}
}
use of com.biglybt.core.diskmanager.file.FMFileManagerException in project BiglyBT by BiglySoftware.
the class FMFileImpl method closeSupport.
protected void closeSupport(boolean explicit) throws FMFileManagerException {
FMFileManagerException flush_exception = null;
try {
flush();
} catch (FMFileManagerException e) {
flush_exception = e;
}
if (fa == null) {
if (explicit) {
releaseFile();
deleteDirs();
}
} else {
try {
fa.close();
} catch (Throwable e) {
throw (new FMFileManagerException("close fails", e));
} finally {
fa = null;
if (explicit) {
releaseFile();
}
}
}
if (flush_exception != null) {
throw (flush_exception);
}
}
use of com.biglybt.core.diskmanager.file.FMFileManagerException in project BiglyBT by BiglySoftware.
the class FMFileAccessLinear method read.
public void read(RandomAccessFile raf, DirectByteBuffer buffer, long offset) throws FMFileManagerException {
if (raf == null) {
throw new FMFileManagerException("read: raf is null");
}
FileChannel fc = raf.getChannel();
if (!fc.isOpen()) {
Debug.out("FileChannel is closed: " + owner.getName());
throw (new FMFileManagerException("read - file is closed"));
}
AEThread2.setDebug(owner);
try {
if (USE_MMAP) {
long remainingInFile = fc.size() - offset;
long remainingInTargetBuffer = buffer.remaining(DirectByteBuffer.SS_FILE);
MappedByteBuffer buf = fc.map(MapMode.READ_ONLY, offset, Math.min(remainingInFile, remainingInTargetBuffer));
buffer.put(DirectByteBuffer.SS_FILE, buf);
} else {
fc.position(offset);
while (fc.position() < fc.size() && buffer.hasRemaining(DirectByteBuffer.SS_FILE)) buffer.read(DirectByteBuffer.SS_FILE, fc);
}
} catch (Exception e) {
Debug.printStackTrace(e);
throw (new FMFileManagerException("read fails", e));
}
}
Aggregations