Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup #111

Merged
merged 10 commits into from Oct 3, 2019
4 changes: 2 additions & 2 deletions jhdf/config/checkstyle/header.txt
@@ -1,9 +1,9 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
29 changes: 14 additions & 15 deletions jhdf/src/main/java/io/jhdf/AbstractNode.java
@@ -1,27 +1,14 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

import static java.util.stream.Collectors.toMap;

import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.concurrent.ConcurrentException;
import org.apache.commons.lang3.concurrent.LazyInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jhdf.api.Attribute;
import io.jhdf.api.Group;
import io.jhdf.api.Node;
Expand All @@ -32,6 +19,18 @@
import io.jhdf.object.message.AttributeInfoMessage;
import io.jhdf.object.message.AttributeMessage;
import io.jhdf.object.message.Message;
import org.apache.commons.lang3.concurrent.ConcurrentException;
import org.apache.commons.lang3.concurrent.LazyInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toMap;

public abstract class AbstractNode implements Node {
private static final Logger logger = LoggerFactory.getLogger(AbstractNode.class);
Expand Down
17 changes: 8 additions & 9 deletions jhdf/src/main/java/io/jhdf/AttributeImpl.java
@@ -1,28 +1,27 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

import static org.apache.commons.lang3.ClassUtils.primitiveToWrapper;

import java.nio.ByteBuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jhdf.api.Attribute;
import io.jhdf.api.Node;
import io.jhdf.dataset.DatasetReader;
import io.jhdf.dataset.VariableLengthDatasetReader;
import io.jhdf.object.datatype.DataType;
import io.jhdf.object.datatype.VariableLength;
import io.jhdf.object.message.AttributeMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;

import static org.apache.commons.lang3.ClassUtils.primitiveToWrapper;

public class AttributeImpl implements Attribute {
private static final Logger logger = LoggerFactory.getLogger(AttributeImpl.class);
Expand Down
4 changes: 2 additions & 2 deletions jhdf/src/main/java/io/jhdf/Constants.java
@@ -1,12 +1,12 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

public final class Constants {
Expand Down
33 changes: 15 additions & 18 deletions jhdf/src/main/java/io/jhdf/FractalHeap.java
@@ -1,21 +1,18 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

import static io.jhdf.Constants.UNDEFINED_ADDRESS;
import static io.jhdf.Utils.bitsToInt;
import static io.jhdf.Utils.bytesNeededToHoldNumber;
import static io.jhdf.Utils.createSubBuffer;
import static io.jhdf.Utils.readBytesAsUnsignedInt;
import static io.jhdf.Utils.readBytesAsUnsignedLong;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import io.jhdf.exceptions.HdfException;
import io.jhdf.exceptions.UnsupportedHdfException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigInteger;
import java.nio.ByteBuffer;
Expand All @@ -27,11 +24,13 @@
import java.util.NavigableMap;
import java.util.TreeMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jhdf.exceptions.HdfException;
import io.jhdf.exceptions.UnsupportedHdfException;
import static io.jhdf.Constants.UNDEFINED_ADDRESS;
import static io.jhdf.Utils.bitsToInt;
import static io.jhdf.Utils.bytesNeededToHoldNumber;
import static io.jhdf.Utils.createSubBuffer;
import static io.jhdf.Utils.readBytesAsUnsignedInt;
import static io.jhdf.Utils.readBytesAsUnsignedLong;
import static java.nio.ByteOrder.LITTLE_ENDIAN;

/**
* Fractal heap implementation. Used for storing data which can be looked up via
Expand Down Expand Up @@ -59,7 +58,6 @@ public class FractalHeap {

private final int maxDirectBlockSize;
private final long maxSizeOfManagedObjects;
private final long addressOfRootBlock;
private final int idLength;
private final int ioFiltersLength;
private final int currentRowsInRootIndirectBlock;
Expand Down Expand Up @@ -154,7 +152,7 @@ public FractalHeap(HdfFileChannel hdfFc, long address) {

startingRowsInRootIndirectBlock = readBytesAsUnsignedInt(bb, 2);

addressOfRootBlock = readBytesAsUnsignedLong(bb, sb.getSizeOfOffsets());
final long addressOfRootBlock = readBytesAsUnsignedLong(bb, sb.getSizeOfOffsets());

currentRowsInRootIndirectBlock = readBytesAsUnsignedInt(bb, 2);

Expand Down Expand Up @@ -233,7 +231,6 @@ public ByteBuffer getId(ByteBuffer buffer) {
private class IndirectBlock {

private final List<Long> childBlockAddresses;
private final long blockOffset;

private IndirectBlock(long address) {
final int headerSize = 4 + 1 + sb.getSizeOfOffsets() + bytesToStoreOffset
Expand Down Expand Up @@ -261,7 +258,7 @@ private IndirectBlock(long address) {
throw new HdfException("Indirect block read from invalid fractal heap");
}

blockOffset = readBytesAsUnsignedLong(bb, bytesToStoreOffset);
final long blockOffset = readBytesAsUnsignedLong(bb, bytesToStoreOffset);

childBlockAddresses = new ArrayList<>(currentRowsInRootIndirectBlock * tableWidth);
for (int i = 0; i < currentRowsInRootIndirectBlock * tableWidth; i++) {
Expand Down
12 changes: 6 additions & 6 deletions jhdf/src/main/java/io/jhdf/GlobalHeap.java
@@ -1,24 +1,24 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

import static io.jhdf.Utils.createSubBuffer;
import static io.jhdf.Utils.readBytesAsUnsignedInt;
import static io.jhdf.Utils.seekBufferToNextMultipleOfEight;
import io.jhdf.exceptions.HdfException;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import io.jhdf.exceptions.HdfException;
import static io.jhdf.Utils.createSubBuffer;
import static io.jhdf.Utils.readBytesAsUnsignedInt;
import static io.jhdf.Utils.seekBufferToNextMultipleOfEight;

public class GlobalHeap {

Expand Down
27 changes: 13 additions & 14 deletions jhdf/src/main/java/io/jhdf/GroupImpl.java
@@ -1,26 +1,14 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.concurrent.ConcurrentException;
import org.apache.commons.lang3.concurrent.LazyInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jhdf.api.Dataset;
import io.jhdf.api.Group;
import io.jhdf.api.Node;
Expand All @@ -38,6 +26,17 @@
import io.jhdf.object.message.LinkInfoMessage;
import io.jhdf.object.message.LinkMessage;
import io.jhdf.object.message.SymbolTableMessage;
import org.apache.commons.lang3.concurrent.ConcurrentException;
import org.apache.commons.lang3.concurrent.LazyInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class GroupImpl extends AbstractNode implements Group {
private final class ChildrenLazyInitializer extends LazyInitializer<Map<String, Node>> {
Expand Down
13 changes: 6 additions & 7 deletions jhdf/src/main/java/io/jhdf/GroupSymbolTableNode.java
@@ -1,23 +1,22 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

import static java.nio.ByteOrder.LITTLE_ENDIAN;
import io.jhdf.exceptions.HdfException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;
import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jhdf.exceptions.HdfException;
import static java.nio.ByteOrder.LITTLE_ENDIAN;

public class GroupSymbolTableNode {
private static final Logger logger = LoggerFactory.getLogger(GroupSymbolTableNode.class);
Expand Down
35 changes: 16 additions & 19 deletions jhdf/src/main/java/io/jhdf/HdfFile.java
@@ -1,14 +1,26 @@
/*******************************************************************************
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright 2019 James Mudd
*
* MIT License see 'LICENSE' file
******************************************************************************/
*/
package io.jhdf;

import io.jhdf.Superblock.SuperblockV0V1;
import io.jhdf.Superblock.SuperblockV2V3;
import io.jhdf.api.Attribute;
import io.jhdf.api.Dataset;
import io.jhdf.api.Group;
import io.jhdf.api.Node;
import io.jhdf.api.NodeType;
import io.jhdf.exceptions.HdfException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -19,19 +31,6 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jhdf.Superblock.SuperblockV0V1;
import io.jhdf.Superblock.SuperblockV2V3;
import io.jhdf.api.Attribute;
import io.jhdf.api.Dataset;
import io.jhdf.api.Group;
import io.jhdf.api.Node;
import io.jhdf.api.NodeType;
import io.jhdf.exceptions.HdfException;

/**
* The HDF file class this object represents a HDF5 file on disk and provides
* methods to access it.
Expand All @@ -53,9 +52,7 @@ public class HdfFile implements Group, AutoCloseable {
private final File file;
private final HdfFileChannel hdfFc;

private final Superblock superblock;

private final Group rootGroup;
private final Group rootGroup;

private final Set<HdfFile> openExternalFiles = new HashSet<>();

Expand Down Expand Up @@ -84,7 +81,7 @@ public HdfFile(File hdfFile) {
}

// We have a valid HDF5 file so read the full superblock
superblock = Superblock.readSuperblock(fc, offset);
final Superblock superblock = Superblock.readSuperblock(fc, offset);

// Validate the superblock
if (superblock.getBaseAddressByte() != offset) {
Expand Down