Skip to content
Snippets Groups Projects
Commit 5b597ad7 authored by felmer's avatar felmer
Browse files

SP-724, BIS-428: AbstractDataSetPackager.addTo() improved by delegating...

SP-724, BIS-428: AbstractDataSetPackager.addTo() improved by delegating methods to the node instead of the file because of recent improvements in hierarchical content node implementations.

SVN: 29452
parent 59ac4018
No related branches found
No related tags found
No related merge requests found
...@@ -16,16 +16,13 @@ ...@@ -16,16 +16,13 @@
package ch.systemsx.cisd.openbis.dss.generic.server; package ch.systemsx.cisd.openbis.dss.generic.server;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.common.io.IOUtilities;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContent; 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.common.io.hierarchical_content.api.IHierarchicalContentNode;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
...@@ -150,12 +147,11 @@ public abstract class AbstractDataSetPackager ...@@ -150,12 +147,11 @@ public abstract class AbstractDataSetPackager
} }
} else if (file.isFile()) } else if (file.isFile())
{ {
long size = file.length(); long size = node.getFileLength();
long checksum = calculateChecksum(node, file); long checksum = isChecksumNeeded() ? node.getChecksumCRC32() : 0;
try try
{ {
FileInputStream fileInputStream = new FileInputStream(file); addEntry(entryPath, node.getLastModified(), size, checksum, node.getInputStream());
addEntry(entryPath, file.lastModified(), size, checksum, new BufferedInputStream(fileInputStream));
} catch (Exception ex) } catch (Exception ex)
{ {
throw CheckedExceptionTunnel.wrapIfNecessary(ex); throw CheckedExceptionTunnel.wrapIfNecessary(ex);
...@@ -165,28 +161,4 @@ public abstract class AbstractDataSetPackager ...@@ -165,28 +161,4 @@ public abstract class AbstractDataSetPackager
throw new IllegalStateException("Node '" + node.getRelativePath() + "' is a real folder"); throw new IllegalStateException("Node '" + node.getRelativePath() + "' is a real folder");
} }
} }
private long calculateChecksum(IHierarchicalContentNode node, File file)
{
long checksum = 0;
if (isChecksumNeeded())
{
boolean checksumCRC32Precalculated = node.isChecksumCRC32Precalculated();
if (checksumCRC32Precalculated)
{
checksum = node.getChecksumCRC32();
} else
{
try
{
FileInputStream fileInputStream = new FileInputStream(file);
checksum = IOUtilities.getChecksumCRC32(new BufferedInputStream(fileInputStream));
} catch (Exception ex)
{
throw CheckedExceptionTunnel.wrapIfNecessary(ex);
}
}
}
return checksum;
}
} }
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