git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-access/sh-fuse-integration/1.0@179092 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cefc28fda5
commit
7de18e7745
|
@ -21,36 +21,60 @@ public class FileDownload implements SHFile{
|
||||||
InputStream stream;
|
InputStream stream;
|
||||||
AbstractFileItem fileItem;
|
AbstractFileItem fileItem;
|
||||||
|
|
||||||
|
Object monitor = new Object();
|
||||||
|
|
||||||
|
long offset = 0;
|
||||||
|
|
||||||
public FileDownload(FileContainer fileContainer) throws Exception {
|
public FileDownload(FileContainer fileContainer) throws Exception {
|
||||||
stream = fileContainer.download().getStream();
|
stream = fileContainer.download().getStream();
|
||||||
fileItem = fileContainer.get();
|
fileItem = fileContainer.get();
|
||||||
logger.trace("FILE-DOWNLOAD initialized with {} , {}", fileItem.getName(), fileItem.getContent().getSize());
|
logger.trace("FILE-DOWNLOAD initialized with {} , {}", fileItem.getName(), fileItem.getContent().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int read(Pointer buf, @size_t long size, @off_t long offset) {
|
public int read(Pointer buf, @size_t long size, @off_t long offset) {
|
||||||
logger.trace("read called with size {} and offset {} ", size, offset);
|
logger.trace("read called with size {} and offset {} ", size, offset);
|
||||||
|
|
||||||
|
while (this.offset!=offset) {
|
||||||
|
logger.trace("going in wait ({},{})",this.offset, offset);
|
||||||
|
synchronized (monitor) {
|
||||||
|
try {
|
||||||
|
monitor.wait();
|
||||||
|
logger.trace("waking up!!!");
|
||||||
|
} catch (InterruptedException e2) {
|
||||||
|
logger.warn("interrupt exception",e2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int bytesToRead = (int) (size);
|
int bytesToRead = (int) (size);
|
||||||
|
|
||||||
byte[] mybuf = new byte[bytesToRead];
|
byte[] mybuf = new byte[bytesToRead];
|
||||||
int readTotal= 0;;
|
int readTotal= 0;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
int read =0;
|
int read =0;
|
||||||
|
logger.trace("BEFORE: bytes to read {} and read total {} and last read {}", bytesToRead, readTotal, read);
|
||||||
while ((read= stream.read(mybuf, 0 , bytesToRead-readTotal))!=-1 && bytesToRead>readTotal) {
|
while ((read= stream.read(mybuf, 0 , bytesToRead-readTotal))!=-1 && bytesToRead>readTotal) {
|
||||||
buf.put(0, mybuf, 0, read);
|
buf.put(readTotal, mybuf, 0, read);
|
||||||
readTotal+= read;
|
readTotal+= read;
|
||||||
|
logger.trace("INSIDE: bytes to read {} and read total {} and last read {}", bytesToRead, readTotal, read);
|
||||||
}
|
}
|
||||||
|
logger.trace("AFTER: bytes to read {} and read total {} and last read {}", bytesToRead, readTotal, read);
|
||||||
|
|
||||||
logger.trace("bytes to read {} and read total {} and last read {}", bytesToRead, readTotal, read);
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("error in read",e);
|
logger.error("error in read",e);
|
||||||
try {
|
try {
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (IOException e1) {}
|
} catch (IOException e1) {}
|
||||||
return -ErrorCodes.ENOENT();
|
return -ErrorCodes.ENOENT();
|
||||||
|
} finally {
|
||||||
|
this.offset = readTotal+offset;
|
||||||
|
logger.trace("setting offset to {}",this.offset);
|
||||||
|
synchronized (monitor) {
|
||||||
|
monitor.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
logger.trace("work finished!!! {}", readTotal);
|
||||||
return readTotal;
|
return readTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -242,27 +242,29 @@ public class StorageHubFS extends FuseStubFS {
|
||||||
logger.trace("!!! read called in path {} with size {} and offset {} ",path, size, offset);
|
logger.trace("!!! read called in path {} with size {} and offset {} ",path, size, offset);
|
||||||
|
|
||||||
SHFile fileDownload;
|
SHFile fileDownload;
|
||||||
if (tempFiles.containsKey(path)) {
|
synchronized (tempFiles) {
|
||||||
fileDownload = tempFiles.get(path);
|
|
||||||
} else {
|
|
||||||
ItemContainer<? extends Item> item = pathUtils.getPath(path);
|
|
||||||
if (item == null) {
|
|
||||||
return -ErrorCodes.ENOENT();
|
|
||||||
}
|
|
||||||
if (item.getType()!=ContainerType.FILE) {
|
|
||||||
return -ErrorCodes.EISDIR();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
if (tempFiles.containsKey(path)) {
|
||||||
fileDownload = new FileDownload((FileContainer)item);
|
fileDownload = tempFiles.get(path);
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
logger.error("error reading remote file",e);
|
ItemContainer<? extends Item> item = pathUtils.getPath(path);
|
||||||
return -ErrorCodes.ENOENT();
|
if (item == null) {
|
||||||
}
|
return -ErrorCodes.ENOENT();
|
||||||
|
}
|
||||||
|
if (item.getType()!=ContainerType.FILE) {
|
||||||
|
return -ErrorCodes.EISDIR();
|
||||||
|
}
|
||||||
|
|
||||||
tempFiles.put(path, fileDownload);
|
try {
|
||||||
|
fileDownload = new FileDownload((FileContainer)item);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("error reading remote file",e);
|
||||||
|
return -ErrorCodes.ENOENT();
|
||||||
|
}
|
||||||
|
|
||||||
|
tempFiles.put(path, fileDownload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileDownload.read(buf, size, offset);
|
return fileDownload.read(buf, size, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue