diff --git a/bds/source/java/ch/systemsx/cisd/bds/Utilities.java b/bds/source/java/ch/systemsx/cisd/bds/Utilities.java index afac161a4671d6965ec1182af2927e5d7574aa7a..a3da40b3fe4b1513d4576eb720765875517b0e21 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/Utilities.java +++ b/bds/source/java/ch/systemsx/cisd/bds/Utilities.java @@ -140,56 +140,4 @@ public class Utilities throw new DataStructureException("Value of '" + name + "' version file is not a number: " + value); } } - - /** - * Founds a node with given <var>name</var> in given <var>directory</var>. - * - * @param name has the format of a path and may contain <code>/</code> as system-independent default - * name-separator character. - */ - public final static INode tryGetNodeRecursively(final IDirectory directory, final String name) - throws DataStructureException - { - final String path = cleanName(name); - final int index = path.indexOf(Constants.PATH_SEPARATOR); - if (index > -1) - { - final INode node = tryGetNode(directory, path.substring(0, index)); - if (node != null) - { - if (node instanceof IDirectory == false) - { - throw new DataStructureException(String.format("Found node '%s' is expected to be a directory.", - node)); - } - return ((IDirectory) node).tryGetNode(path.substring(index + 1)); - } - } else - { - return tryGetNode(directory, path); - } - return null; - } - - private final static INode tryGetNode(final IDirectory directory, final String name) - { - for (final INode node : directory) - { - if (node.getName().equals(name)) - { - return node; - } - } - return null; - } - - private final static String cleanName(final String name) - { - final int index = name.indexOf(Constants.PATH_SEPARATOR); - if (index == 0) - { - return name.substring(1); - } - return name; - } } \ No newline at end of file diff --git a/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/Directory.java b/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/Directory.java index e7f0baa55aa70d7988f087b455e290b59750f1e6..c3f3e8d32a9a5890b37c59b39ac0f6bc52483301 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/Directory.java +++ b/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/Directory.java @@ -21,7 +21,8 @@ import java.util.Iterator; import org.apache.commons.io.FileUtils; -import ch.systemsx.cisd.bds.Utilities; +import ch.systemsx.cisd.bds.Constants; +import ch.systemsx.cisd.bds.DataStructureException; import ch.systemsx.cisd.bds.storage.IDirectory; import ch.systemsx.cisd.bds.storage.IFile; import ch.systemsx.cisd.bds.storage.ILink; @@ -53,6 +54,57 @@ final class Directory extends AbstractNode implements IDirectory return ((AbstractNode) node).nodeFile; } + /** + * Founds a node with given <var>name</var> in given <var>directory</var>. + * + * @param name has the format of a path and may contain <code>/</code> as system-independent default + * name-separator character. + */ + private final static INode tryGetNodeRecursively(final IDirectory directory, final String name) + throws DataStructureException + { + final String path = cleanName(name); + final int index = path.indexOf(Constants.PATH_SEPARATOR); + if (index > -1) + { + final INode node = tryGetNode(directory, path.substring(0, index)); + if (node != null) + { + if (node instanceof IDirectory == false) + { + throw new DataStructureException(String.format("Found node '%s' is expected to be a directory.", + node)); + } + return ((IDirectory) node).tryGetNode(path.substring(index + 1)); + } + } else + { + return tryGetNode(directory, path); + } + return null; + } + + private final static INode tryGetNode(final IDirectory directory, final String name) + { + for (final INode node : directory) + { + if (node.getName().equals(name)) + { + return node; + } + } + return null; + } + + private final static String cleanName(final String name) + { + final int index = name.indexOf(Constants.PATH_SEPARATOR); + if (index == 0) + { + return name.substring(1); + } + return name; + } // // IDirectory @@ -61,7 +113,7 @@ final class Directory extends AbstractNode implements IDirectory public final INode tryGetNode(final String name) { assert name != null : "Given name can not be null."; - return Utilities.tryGetNodeRecursively(this, name); + return tryGetNodeRecursively(this, name); } public final IDirectory makeDirectory(final String name) diff --git a/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/File.java b/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/File.java index 57e1f64cb4c488f3f0314a56ef24844c6b7885bf..791d86e882814a8ad46a91df6829109cf937705d 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/File.java +++ b/bds/source/java/ch/systemsx/cisd/bds/storage/filesystem/File.java @@ -25,9 +25,7 @@ import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import ch.systemsx.cisd.bds.DataStructureException; import ch.systemsx.cisd.bds.storage.IFile; -import ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.utilities.FileUtilities; @@ -76,24 +74,12 @@ final class File extends AbstractNode implements IFile public final String getStringContent() { - try - { - return FileUtilities.loadToString(nodeFile); - } catch (CheckedExceptionTunnel ex) - { - throw new DataStructureException(ex.getMessage()); - } + return FileUtilities.loadToString(nodeFile); } public final List<String> getStringContentList() { - try - { - return FileUtilities.loadToStringList(nodeFile); - } catch (CheckedExceptionTunnel ex) - { - throw new DataStructureException(ex.getMessage()); - } + return FileUtilities.loadToStringList(nodeFile); } public final void extractTo(final java.io.File directory) throws EnvironmentFailureException