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
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
......@@ -71,36 +72,27 @@ import java.util.Map;
*/
public class SLUBStoragePlugin extends AbstractStorageHandler {
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 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() {
log.info("SLUBStoragePlugin instantiated");
}
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier)
throws Exception
{
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) {
log.info("SLUBStoragePlugin.checkFixity()");
return checkFixity(fixities, storedEntityIdentifier, true);
}
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier, boolean isRelativePath)
throws Exception
{
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier, boolean isRelativePath) {
log.info("SLUBStoragePlugin.checkFixity() storedEntityIdentifier='" + storedEntityIdentifier + "' isRelativePath=" + isRelativePath);
boolean result = true;
if (fixities != null)
{
InputStream is = null;
InputStream is;
try {
is = retrieveEntity(storedEntityIdentifier, isRelativePath);
Checksummer checksummer = new Checksummer(is, true, true, true,true);
for (Fixity fixity : fixities) {
fixity.setResult(false);
fixity.setResult(Boolean.FALSE);
log.info("SLUBStoragePlugin.checkFixity() getAlgorithm=" + fixity.getAlgorithm());
log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.MD5=" + Fixity.FixityAlgorithm.MD5.toString());
log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.SHA1=" + Fixity.FixityAlgorithm.SHA1.toString());
......@@ -137,10 +129,6 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
finally
{
log.info("SLUBStoragePlugin.checkFixity() finally called");
if (is != null) {
log.info("SLUBStoragePlugin.checkFixity()is closed");
is.close();
}
}
}
return result;
......@@ -243,14 +231,15 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
throws IOException
{
log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "' isrelative=" + isRelative);
File file = new File((isRelative ? this.parameters.get("DIR_ROOT") : "") + storedEntityIdentifier);
return java.nio.file.Files.newInputStream( file.toPath());
var pathname = (isRelative ? this.parameters.get("DIR_ROOT") : "") + storedEntityIdentifier;
return java.nio.file.Files.newInputStream( Paths.get( pathname));
}
public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end)
{
log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + " end=" + end);
byte[] bytes = new byte[(int)(end - start + 1L)];
RandomAccessFile file = null;
RandomAccessFile file;
try
{
file = new RandomAccessFile(this.parameters.get("DIR_ROOT") + storedEntityIdentifier, "r");
......@@ -266,16 +255,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
}
finally
{
if (file != null) {
try
{
file.close();
}
catch (Exception e)
{
log.error("Failed closing file", e.getMessage());
}
}
log.info("SLUBStoragePlugin.retrieveEntityByRange() finally called");
}
return bytes;
}
......@@ -322,8 +302,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
OutputStream output = null;
try
{
File file = new File(destFilePath);
output = java.nio.file.Files.newOutputStream( file.toPath());
output = java.nio.file.Files.newOutputStream( Paths.get( destFilePath));
IOUtil.copy(is, output);
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