Skip to content
Snippets Groups Projects
Commit 10f0f497 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- removed unused variables

- fixed unnessecary exception declarations if method does not throw exceptions
- simplified code
parent faab9fac
Branches
Tags
No related merge requests found
...@@ -39,6 +39,7 @@ import java.io.IOException; ...@@ -39,6 +39,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -71,36 +72,27 @@ import java.util.Map; ...@@ -71,36 +72,27 @@ import java.util.Map;
*/ */
public class SLUBStoragePlugin extends AbstractStorageHandler { public class SLUBStoragePlugin extends AbstractStorageHandler {
private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class); private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class);
private static final String DIR_PREFIX = "DIR_PREFIX";
private static final String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */ private static final String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */
private static final String FILE_PER_DIR = "FILE_PER_DIR";
private static final String FILES_HANDLING_METHOD = "FILES_HANDLING_METHOD";
final String RELATIVE_DIRECTORY_PATH = "relativeDirectoryPath";
final String DEST_FILE_PATH = "destFilePath";
public SLUBStoragePlugin() { public SLUBStoragePlugin() {
log.info("SLUBStoragePlugin instantiated"); log.info("SLUBStoragePlugin instantiated");
} }
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) {
throws Exception
{
log.info("SLUBStoragePlugin.checkFixity()"); log.info("SLUBStoragePlugin.checkFixity()");
return checkFixity(fixities, storedEntityIdentifier, true); return checkFixity(fixities, storedEntityIdentifier, true);
} }
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier, boolean isRelativePath) public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier, boolean isRelativePath) {
throws Exception
{
log.info("SLUBStoragePlugin.checkFixity() storedEntityIdentifier='" + storedEntityIdentifier + "' isRelativePath=" + isRelativePath); log.info("SLUBStoragePlugin.checkFixity() storedEntityIdentifier='" + storedEntityIdentifier + "' isRelativePath=" + isRelativePath);
boolean result = true; boolean result = true;
if (fixities != null) if (fixities != null)
{ {
InputStream is = null; InputStream is;
try { try {
is = retrieveEntity(storedEntityIdentifier, isRelativePath); is = retrieveEntity(storedEntityIdentifier, isRelativePath);
Checksummer checksummer = new Checksummer(is, true, true, true,true); Checksummer checksummer = new Checksummer(is, true, true, true,true);
for (Fixity fixity : fixities) { for (Fixity fixity : fixities) {
fixity.setResult(false); fixity.setResult(Boolean.FALSE);
log.info("SLUBStoragePlugin.checkFixity() getAlgorithm=" + fixity.getAlgorithm()); log.info("SLUBStoragePlugin.checkFixity() getAlgorithm=" + fixity.getAlgorithm());
log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.MD5=" + Fixity.FixityAlgorithm.MD5.toString()); log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.MD5=" + Fixity.FixityAlgorithm.MD5.toString());
log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.SHA1=" + Fixity.FixityAlgorithm.SHA1.toString()); log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.SHA1=" + Fixity.FixityAlgorithm.SHA1.toString());
...@@ -137,10 +129,6 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -137,10 +129,6 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
finally finally
{ {
log.info("SLUBStoragePlugin.checkFixity() finally called"); log.info("SLUBStoragePlugin.checkFixity() finally called");
if (is != null) {
log.info("SLUBStoragePlugin.checkFixity()is closed");
is.close();
}
} }
} }
return result; return result;
...@@ -243,14 +231,15 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -243,14 +231,15 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
throws IOException throws IOException
{ {
log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "' isrelative=" + isRelative); log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "' isrelative=" + isRelative);
File file = new File((isRelative ? this.parameters.get("DIR_ROOT") : "") + storedEntityIdentifier); var pathname = (isRelative ? this.parameters.get("DIR_ROOT") : "") + storedEntityIdentifier;
return java.nio.file.Files.newInputStream( file.toPath());
return java.nio.file.Files.newInputStream( Paths.get( pathname));
} }
public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end)
{ {
log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + " end=" + end); log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + " end=" + end);
byte[] bytes = new byte[(int)(end - start + 1L)]; byte[] bytes = new byte[(int)(end - start + 1L)];
RandomAccessFile file = null; RandomAccessFile file;
try try
{ {
file = new RandomAccessFile(this.parameters.get("DIR_ROOT") + storedEntityIdentifier, "r"); file = new RandomAccessFile(this.parameters.get("DIR_ROOT") + storedEntityIdentifier, "r");
...@@ -266,16 +255,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -266,16 +255,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
} }
finally finally
{ {
if (file != null) { log.info("SLUBStoragePlugin.retrieveEntityByRange() finally called");
try
{
file.close();
}
catch (Exception e)
{
log.error("Failed closing file", e.getMessage());
}
}
} }
return bytes; return bytes;
} }
...@@ -322,8 +302,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -322,8 +302,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
OutputStream output = null; OutputStream output = null;
try try
{ {
File file = new File(destFilePath); output = java.nio.file.Files.newOutputStream( Paths.get( destFilePath));
output = java.nio.file.Files.newOutputStream( file.toPath());
IOUtil.copy(is, output); IOUtil.copy(is, output);
log.debug("SLUBStoragePlugin.storeEntity() try copy was successfull"); log.debug("SLUBStoragePlugin.storeEntity() try copy was successfull");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment