Skip to content
Snippets Groups Projects
Commit 2f0f1248 authored by jakubs's avatar jakubs
Browse files

SSDM-3907: improve behavior for getting file streams

SVN: 36868
parent 49a79a95
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@ class V3HierarchicalContentResolver implements V3Resolver
if (false == rootNode.isDirectory())
{
return new V3FtpFileResponse(fullPath, rootNode);
return new V3FtpFileResponse(fullPath, rootNode, content);
}
V3FtpDirectoryResponse response = new V3FtpDirectoryResponse(fullPath);
......
......@@ -22,17 +22,22 @@ import java.util.List;
import org.apache.ftpserver.ftplet.FtpFile;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.HierarchicalContentUtils;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContent;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode;
import ch.systemsx.cisd.openbis.dss.generic.server.ftp.resolver.AbstractFtpFile;
public class V3FtpFileResponse extends AbstractFtpFile implements V3FtpFile
{
private IHierarchicalContentNode node;
private final IHierarchicalContentNode node;
public V3FtpFileResponse(String fullPath, final IHierarchicalContentNode node)
private final IHierarchicalContent content;
public V3FtpFileResponse(String fullPath, final IHierarchicalContentNode node, final IHierarchicalContent content)
{
super(fullPath);
this.node = node;
this.content = content;
}
@Override
......@@ -56,7 +61,25 @@ public class V3FtpFileResponse extends AbstractFtpFile implements V3FtpFile
@Override
public InputStream createInputStream(long offset) throws IOException
{
return node.getInputStream();
try
{
InputStream result =
HierarchicalContentUtils.getInputStreamAutoClosingContent(node, content);
if (offset > 0)
{
result.skip(offset);
}
return result;
} catch (IOException ioex)
{
content.close();
throw ioex;
} catch (RuntimeException re)
{
content.close();
throw re;
}
}
@Override
......
......@@ -79,10 +79,10 @@ public class V3DataSetTypeResolver implements V3Resolver
if (requestedFileName != null)
{
IHierarchicalContentNode result = findRequestedNode(dataSetsToSearch, requestedFileName, context.getContentProvider());
V3FtpFileResponse result = findRequestedNode(fullPath, dataSetsToSearch, requestedFileName, context.getContentProvider());
if (result != null)
{
return new V3FtpFileResponse(fullPath, result);
return result;
} else
{
return new V3FtpNonExistingFile(fullPath, "Unable to locate requested file");
......@@ -123,16 +123,16 @@ public class V3DataSetTypeResolver implements V3Resolver
return result;
}
private IHierarchicalContentNode findRequestedNode(List<DataSet> dataSetsToSearch, String requestedFileName,
private V3FtpFileResponse findRequestedNode(String fullPath, List<DataSet> dataSetsToSearch, String requestedFileName,
IHierarchicalContentProvider contentProvider)
{
for (DataSet dataSet : dataSetsToSearch)
{
IHierarchicalContent content = contentProvider.asContent(dataSet.getCode());
IHierarchicalContentNode result = findRequestedNode(content.getRootNode(), requestedFileName);
if (result != null)
IHierarchicalContentNode node = findRequestedNode(content.getRootNode(), requestedFileName);
if (node != null)
{
return result;
return new V3FtpFileResponse(fullPath, node, content);
}
}
return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment