Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[MOD] Adapted poms to point to sirixdb/sirix repository plus simple

changes.
  • Loading branch information...
commit 13d20f0086e63ef351557842091257562fa9119f 1 parent 3df2715
@JohannesLichtenberger JohannesLichtenberger authored
Showing with 512 additions and 449 deletions.
  1. +25 −10 bundles/sirix-core/src/main/java/org/sirix/cache/PageBinding.java
  2. +28 −15 bundles/sirix-core/src/main/java/org/sirix/cache/PageContainerBinding.java
  3. +17 −5 bundles/sirix-core/src/main/java/org/sirix/cache/RecordPageContainer.java
  4. +6 −3 bundles/sirix-core/src/main/java/org/sirix/index/bplustree/BPlusInnerNodePage.java
  5. +4 −2 bundles/sirix-core/src/main/java/org/sirix/index/bplustree/BPlusLeafNodePage.java
  6. +6 −5 bundles/sirix-core/src/main/java/org/sirix/index/name/Names.java
  7. +16 −15 bundles/sirix-core/src/main/java/org/sirix/io/berkeley/binding/PageBinding.java
  8. +11 −10 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/ByteHandlePipeline.java
  9. +7 −5 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/ByteHandler.java
  10. +12 −57 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/DeflateCompressor.java
  11. +19 −43 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/Encryptor.java
  12. +11 −21 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/SnappyCompressor.java
  13. +4 −5 bundles/sirix-core/src/main/java/org/sirix/io/file/FileReader.java
  14. +16 −9 bundles/sirix-core/src/main/java/org/sirix/io/file/FileWriter.java
  15. +86 −86 bundles/sirix-core/src/main/java/org/sirix/node/Kind.java
  16. +8 −7 bundles/sirix-core/src/main/java/org/sirix/node/NodePersistenter.java
  17. +6 −2 bundles/sirix-core/src/main/java/org/sirix/node/Utils.java
  18. +12 −4 bundles/sirix-core/src/main/java/org/sirix/node/interfaces/RecordPersistenter.java
  19. +4 −2 bundles/sirix-core/src/main/java/org/sirix/page/AbstractForwardingPage.java
  20. +5 −4 bundles/sirix-core/src/main/java/org/sirix/page/CASPage.java
  21. +4 −3 bundles/sirix-core/src/main/java/org/sirix/page/IndirectPage.java
  22. +5 −4 bundles/sirix-core/src/main/java/org/sirix/page/NamePage.java
  23. +6 −5 bundles/sirix-core/src/main/java/org/sirix/page/OverflowPage.java
  24. +48 −48 bundles/sirix-core/src/main/java/org/sirix/page/PageKind.java
  25. +12 −7 bundles/sirix-core/src/main/java/org/sirix/page/PagePersistenter.java
  26. +7 −4 bundles/sirix-core/src/main/java/org/sirix/page/PathPage.java
  27. +5 −4 bundles/sirix-core/src/main/java/org/sirix/page/PathSummaryPage.java
  28. +6 −4 bundles/sirix-core/src/main/java/org/sirix/page/RevisionRootPage.java
  29. +6 −4 bundles/sirix-core/src/main/java/org/sirix/page/UberPage.java
  30. +29 −18 bundles/sirix-core/src/main/java/org/sirix/page/UnorderedKeyValuePage.java
  31. +8 −4 bundles/sirix-core/src/main/java/org/sirix/page/delegates/PageDelegate.java
  32. +7 −4 bundles/sirix-core/src/main/java/org/sirix/page/interfaces/Page.java
  33. +2 −2 bundles/sirix-core/src/test/java/org/sirix/TestHelper.java
  34. +41 −8 bundles/sirix-core/src/test/java/org/sirix/io/bytepipe/ByteHandlerTest.java
  35. +11 −8 bundles/sirix-core/src/test/java/org/sirix/node/AttributeNodeTest.java
  36. +1 −1  bundles/sirix-core/src/test/java/org/sirix/page/NodePageTest.java
  37. +2 −2 bundles/sirix-distributed/pom.xml
  38. +2 −2 bundles/sirix-fs/pom.xml
  39. +2 −2 bundles/sirix-gui/pom.xml
  40. +1 −1  bundles/sirix-gui/src/main/java/org/sirix/gui/view/smallmultiple/SmallmultipleControl.java
  41. +1 −1  bundles/sirix-gui/src/main/java/org/sirix/gui/view/smallmultiple/SmallmultipleGUI.java
  42. +2 −2 bundles/sirix-jax-rx/pom.xml
  43. +1 −1  bundles/sirix-xquery/pom.xml
View
35 bundles/sirix-core/src/main/java/org/sirix/cache/PageBinding.java
@@ -27,16 +27,21 @@
package org.sirix.cache;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
import javax.annotation.Nullable;
import org.sirix.access.conf.ResourceConfiguration;
import org.sirix.api.PageReadTrx;
import org.sirix.page.PagePersistenter;
import org.sirix.page.interfaces.Page;
+import org.sirix.utils.LogWrapper;
+import org.slf4j.LoggerFactory;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;
@@ -44,8 +49,10 @@
/**
* Binding for {@link RecordPageContainer} reference.
*/
-public class PageBinding extends TupleBinding<Page> {
+public final class PageBinding extends TupleBinding<Page> {
+ private static final LogWrapper LOGGER = new LogWrapper(LoggerFactory.getLogger(PageBinding.class));
+
/** {@link ResourceConfiguration} instance. */
private final PageReadTrx mPageReadTrx;
@@ -65,19 +72,27 @@ public Page entryToObject(final @Nullable TupleInput input) {
if (input == null) {
return null;
}
- final ByteArrayDataInput source = ByteStreams.newDataInput(input
- .getBufferBytes());
- return PagePersistenter.deserializePage(source, mPageReadTrx);
+ try {
+ return PagePersistenter.deserializePage(new DataInputStream(input),
+ mPageReadTrx);
+ } catch (final IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ return null;
+ }
}
@Override
public void objectToEntry(final @Nullable Page page,
final @Nullable TupleOutput output) {
if (page != null && output != null) {
- final ByteArrayDataOutput target = ByteStreams.newDataOutput();
+ final OutputStream target = new ByteArrayOutputStream();
final byte[] bytes = output.getBufferBytes();
- target.write(bytes, 0, bytes.length);
- page.serialize(target);
+ try {
+ target.write(bytes, 0, bytes.length);
+ page.serialize(new DataOutputStream(target));
+ } catch (final IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
}
}
}
View
43 bundles/sirix-core/src/main/java/org/sirix/cache/PageContainerBinding.java
@@ -27,15 +27,19 @@
package org.sirix.cache;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
import javax.annotation.Nullable;
import org.sirix.access.conf.ResourceConfiguration;
import org.sirix.api.PageReadTrx;
import org.sirix.page.PagePersistenter;
import org.sirix.page.interfaces.KeyValuePage;
+import org.sirix.utils.LogWrapper;
+import org.slf4j.LoggerFactory;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteStreams;
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;
@@ -43,9 +47,13 @@
/**
* Binding for {@link RecordPageContainer} reference.
*/
-public class PageContainerBinding<T extends KeyValuePage<?, ?>> extends
+public final class PageContainerBinding<T extends KeyValuePage<?, ?>> extends
TupleBinding<RecordPageContainer<T>> {
+ /** Logger. */
+ private static final LogWrapper LOGGER = new LogWrapper(
+ LoggerFactory.getLogger(PageContainerBinding.class));
+
/** {@link ResourceConfiguration} instance. */
private final PageReadTrx mPageReadTrx;
@@ -60,24 +68,29 @@ public PageContainerBinding(final PageReadTrx pageReadTrx) {
mPageReadTrx = pageReadTrx;
}
-
@Override
- public RecordPageContainer<T> entryToObject(
- final @Nullable TupleInput input) {
+ public RecordPageContainer<T> entryToObject(final @Nullable TupleInput input) {
if (input == null) {
@SuppressWarnings("unchecked")
final RecordPageContainer<T> emptyInstance = (RecordPageContainer<T>) RecordPageContainer.EMPTY_INSTANCE;
return emptyInstance;
}
- final ByteArrayDataInput source = ByteStreams.newDataInput(input
- .getBufferBytes());
- @SuppressWarnings("unchecked")
- final T current = (T) PagePersistenter
- .deserializePage(source, mPageReadTrx);
- @SuppressWarnings("unchecked")
- final T modified = (T) PagePersistenter
- .deserializePage(source, mPageReadTrx);
- return new RecordPageContainer<T>(current, modified);
+ final DataInputStream source = new DataInputStream(
+ new ByteArrayInputStream(input.getBufferBytes()));
+ try {
+ @SuppressWarnings("unchecked")
+ final T current = (T) PagePersistenter.deserializePage(source,
+ mPageReadTrx);
+ @SuppressWarnings("unchecked")
+ final T modified = (T) PagePersistenter.deserializePage(source,
+ mPageReadTrx);
+ return new RecordPageContainer<T>(current, modified);
+ } catch (final IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ @SuppressWarnings("unchecked")
+ final RecordPageContainer<T> emptyInstance = (RecordPageContainer<T>) RecordPageContainer.EMPTY_INSTANCE;
+ return emptyInstance;
+ }
}
@Override
View
22 bundles/sirix-core/src/main/java/org/sirix/cache/RecordPageContainer.java
@@ -27,15 +27,19 @@
package org.sirix.cache;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import javax.annotation.Nullable;
import org.sirix.page.PagePersistenter;
import org.sirix.page.UnorderedKeyValuePage;
import org.sirix.page.interfaces.KeyValuePage;
+import org.sirix.utils.LogWrapper;
+import org.slf4j.LoggerFactory;
import com.google.common.base.Objects;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
import com.sleepycat.bind.tuple.TupleOutput;
/**
@@ -61,6 +65,9 @@
*/
public final class RecordPageContainer<T extends KeyValuePage<?, ?>> {
+ /** Logger. */
+ private static final LogWrapper LOGGER = new LogWrapper(LoggerFactory.getLogger(RecordPageContainer.class));
+
/**
* {@link UnorderedKeyValuePage} reference, which references the complete
* key/value page.
@@ -149,9 +156,14 @@ public T getModified() {
* for serialization
*/
public void serialize(final TupleOutput out) {
- final ByteArrayDataOutput sink = ByteStreams.newDataOutput();
- PagePersistenter.serializePage(sink, mComplete);
- PagePersistenter.serializePage(sink, mModified);
+ final ByteArrayOutputStream sink = new ByteArrayOutputStream();
+ final DataOutputStream dataOut = new DataOutputStream(sink);
+ try {
+ PagePersistenter.serializePage(dataOut, mComplete);
+ PagePersistenter.serializePage(dataOut, mModified);
+ } catch (final IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
out.write(sink.toByteArray());
}
View
9 bundles/sirix-core/src/main/java/org/sirix/index/bplustree/BPlusInnerNodePage.java
@@ -1,5 +1,7 @@
package org.sirix.index.bplustree;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
@@ -103,7 +105,8 @@ public BPlusInnerNodePage(final @Nonnegative long recordPageKey,
*/
protected BPlusInnerNodePage(final ByteArrayDataInput in,
final PageReadTrx pageReadTrx) {
- mDelegate = new PageDelegate(Constants.INP_REFERENCE_COUNT, in);
+ mDelegate = null;
+// mDelegate = new PageDelegate(Constants.INP_REFERENCE_COUNT, in);
mRecordPageKey = in.readLong();
final int size = in.readInt();
mRecords = new TreeMap<>();
@@ -132,7 +135,7 @@ public void setRightPage(final Optional<PageReference> rightPage) {
}
@Override
- public void serialize(final ByteArrayDataOutput out) {
+ public void serialize(final DataOutputStream out) throws IOException {
super.serialize(out);
out.writeLong(mRecordPageKey);
out.writeInt(mRecords.size());
@@ -147,7 +150,7 @@ public void serialize(final ByteArrayDataOutput out) {
}
private void serializePointer(final Optional<PageReference> page,
- final ByteArrayDataOutput out) {
+ final DataOutputStream out) throws IOException {
if (page.isPresent()) {
out.writeBoolean(page.get().getKey() == org.sirix.settings.Constants.NULL_ID ? false
: true);
View
6 bundles/sirix-core/src/main/java/org/sirix/index/bplustree/BPlusLeafNodePage.java
@@ -1,5 +1,7 @@
package org.sirix.index.bplustree;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
@@ -131,7 +133,7 @@ public void setRightPage(final Optional<PageReference> rightPage) {
}
@Override
- public void serialize(final ByteArrayDataOutput out) {
+ public void serialize(final DataOutputStream out) throws IOException {
out.writeLong(mRecordPageKey);
serializePointer(mLeftPage, out);
serializePointer(mRightPage, out);
@@ -144,7 +146,7 @@ public void serialize(final ByteArrayDataOutput out) {
}
private void serializePointer(final Optional<PageReference> page,
- final ByteArrayDataOutput out) {
+ final DataOutputStream out) throws IOException {
if (page.isPresent()) {
out.writeBoolean(page.get().getKey() == org.sirix.settings.Constants.NULL_ID ? false
: true);
View
11 bundles/sirix-core/src/main/java/org/sirix/index/name/Names.java
@@ -2,6 +2,9 @@
import static com.google.common.base.Preconditions.checkNotNull;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -9,8 +12,6 @@
import org.sirix.settings.Constants;
import com.google.common.collect.HashBiMap;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
/**
* Names index structure.
@@ -40,7 +41,7 @@ private Names() {
* @param in
* the persistent storage
*/
- private Names(final ByteArrayDataInput in) {
+ private Names(final DataInputStream in) throws IOException {
final int mapSize = in.readInt();
mNameMap = HashBiMap.create(mapSize);
mCountNameMapping = new HashMap<>(mapSize);
@@ -62,7 +63,7 @@ private Names(final ByteArrayDataInput in) {
* @param out
* the persistent storage
*/
- public void serialize(final ByteArrayDataOutput out) {
+ public void serialize(final DataOutputStream out) throws IOException {
out.writeInt(mNameMap.size());
for (final Entry<Integer, byte[]> entry : mNameMap.entrySet()) {
out.writeInt(entry.getKey());
@@ -179,7 +180,7 @@ public static Names getInstance() {
* input source, the persistent storage
* @return cloned index
*/
- public static Names clone(final ByteArrayDataInput in) {
+ public static Names clone(final DataInputStream in) throws IOException {
return new Names(in);
}
}
View
31 bundles/sirix-core/src/main/java/org/sirix/io/berkeley/binding/PageBinding.java
@@ -27,8 +27,11 @@
package org.sirix.io.berkeley.binding;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import org.sirix.api.PageReadTrx;
-import org.sirix.exception.SirixIOException;
import org.sirix.io.bytepipe.ByteHandlePipeline;
import org.sirix.page.PagePersistenter;
import org.sirix.page.delegates.PageDelegate;
@@ -36,8 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;
@@ -71,7 +72,7 @@ public PageBinding(final PageBinding pageBinding) {
mByteHandler = new ByteHandlePipeline(pageBinding.mByteHandler);
mPageReadTrx = pageBinding.mPageReadTrx;
}
-
+
/**
* Constructor.
*
@@ -89,7 +90,7 @@ public PageBinding(final ByteHandlePipeline byteHandler) {
* @param byteHandler
* byte handler pipleine
* @param pageReadTrx
- * page reading transaction
+ * page reading transaction
*/
public PageBinding(final ByteHandlePipeline byteHandler,
final PageReadTrx pageReadTrx) {
@@ -100,23 +101,23 @@ public PageBinding(final ByteHandlePipeline byteHandler,
@Override
public Page entryToObject(final TupleInput input) {
- byte[] deserialized = new byte[0];
try {
- deserialized = mByteHandler.deserialize(input.getBufferBytes());
- } catch (final SirixIOException e) {
+ return PagePersistenter.deserializePage(
+ new DataInputStream(mByteHandler.deserialize(input)), mPageReadTrx);
+ } catch (final IOException e) {
LOGGER.error(e.getMessage(), e);
+ return null;
}
- return PagePersistenter.deserializePage(
- ByteStreams.newDataInput(deserialized), mPageReadTrx);
- }
+ }
@Override
public void objectToEntry(final Page page, final TupleOutput output) {
- final ByteArrayDataOutput outputData = ByteStreams.newDataOutput();
- PagePersistenter.serializePage(outputData, page);
try {
- output.write(mByteHandler.serialize(outputData.toByteArray()));
- } catch (final SirixIOException e) {
+ final DataOutputStream outputData = new DataOutputStream(output);
+ PagePersistenter.serializePage(outputData, page);
+ mByteHandler.serialize(outputData);
+ output.close();
+ } catch (final IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
View
21 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/ByteHandlePipeline.java
@@ -3,12 +3,13 @@
*/
package org.sirix.io.bytepipe;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.sirix.exception.SirixIOException;
-
/**
* Pipeline to handle Bytes before stored in the backends.
*
@@ -48,9 +49,9 @@ public ByteHandlePipeline(final ByteHandler... parts) {
}
@Override
- public byte[] serialize(final byte[] toSerialize)
- throws SirixIOException {
- byte[] pipeData = toSerialize;
+ public OutputStream serialize(final OutputStream toSerialize)
+ throws IOException {
+ OutputStream pipeData = toSerialize;
for (final ByteHandler part : mParts) {
pipeData = part.serialize(pipeData);
}
@@ -58,11 +59,11 @@ public ByteHandlePipeline(final ByteHandler... parts) {
}
@Override
- public byte[] deserialize(final byte[] toDeserialize)
- throws SirixIOException {
- byte[] pipeData = toDeserialize;
- for (int i = mParts.size() - 1; i >= 0; i--) {
- pipeData = mParts.get(i).deserialize(pipeData);
+ public InputStream deserialize(final InputStream toDeserialize)
+ throws IOException {
+ InputStream pipeData = toDeserialize;
+ for (final ByteHandler part : mParts) {
+ pipeData = part.deserialize(pipeData);
}
return pipeData;
}
View
12 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/ByteHandler.java
@@ -1,6 +1,8 @@
package org.sirix.io.bytepipe;
-import org.sirix.exception.SirixIOException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
/**
* Interface for the decorator, representing any byte representation to be
@@ -17,10 +19,10 @@
* @param toSerialize
* byte to be serialized
* @return result of the serialization
- * @throws SirixIOException
+ * @throws IOException
* if a byte handling exception occurs
*/
- byte[] serialize(byte[] toSerialize) throws SirixIOException;
+ OutputStream serialize(OutputStream pToSerialize) throws IOException;
/**
* Method to deserialize any byte-chunk.
@@ -28,10 +30,10 @@
* @param toDeserialize
* to deserialize
* @return result of the deserialization
- * @throws SirixIOException
+ * @throws IOException
* if a byte handling exception occurs
*/
- byte[] deserialize(byte[] toDeserialize) throws SirixIOException;
+ InputStream deserialize(InputStream toDeserialize) throws IOException;
/**
* Method to retrieve a new instance.
View
69 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/DeflateCompressor.java
@@ -3,12 +3,11 @@
*/
package org.sirix.io.bytepipe;
-import java.io.ByteArrayOutputStream;
-import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-
-import org.sirix.exception.SirixIOException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.InflaterInputStream;
/**
* Decorator to zip any data.
@@ -16,62 +15,18 @@
* @author Sebastian Graf, University of Konstanz
*
*/
-public class DeflateCompressor implements ByteHandler {
-
- /** {@link Deflater} instance. */
- private final Deflater mCompressor;
-
- /** {@link Inflater} instance. */
- private final Inflater mDecompressor;
-
- private final byte[] mTmp;
-
- /** {@link ByteArrayOutputStream} instance. */
- private final ByteArrayOutputStream mOut;
-
- /**
- * Constructor.
- */
- public DeflateCompressor() {
- mCompressor = new Deflater();
- mDecompressor = new Inflater();
- mTmp = new byte[32767];
- mOut = new ByteArrayOutputStream();
- }
+public final class DeflateCompressor implements ByteHandler {
@Override
- public byte[] serialize(final byte[] toSerialize)
- throws SirixIOException {
- mCompressor.reset();
- mOut.reset();
- mCompressor.setInput(toSerialize);
- mCompressor.finish();
- int count;
- while (!mCompressor.finished()) {
- count = mCompressor.deflate(mTmp);
- mOut.write(mTmp, 0, count);
- }
- final byte[] result = mOut.toByteArray();
- return result;
+ public OutputStream serialize(final OutputStream toSerialize)
+ throws IOException {
+ return new DeflaterOutputStream(toSerialize);
}
@Override
- public byte[] deserialize(final byte[] toDeserialize)
- throws SirixIOException {
- mDecompressor.reset();
- mOut.reset();
- mDecompressor.setInput(toDeserialize);
- int count;
- while (!mDecompressor.finished()) {
- try {
- count = mDecompressor.inflate(mTmp);
- } catch (final DataFormatException e) {
- throw new SirixIOException(e);
- }
- mOut.write(mTmp, 0, count);
- }
- final byte[] result = mOut.toByteArray();
- return result;
+ public InputStream deserialize(final InputStream toDeserialize)
+ throws IOException {
+ return new InflaterInputStream(toDeserialize);
}
@Override
View
62 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/Encryptor.java
@@ -3,13 +3,15 @@
*/
package org.sirix.io.bytepipe;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.security.GeneralSecurityException;
-import java.security.InvalidKeyException;
import java.security.Key;
-import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
-import javax.crypto.NoSuchPaddingException;
+import javax.crypto.CipherInputStream;
+import javax.crypto.CipherOutputStream;
import javax.crypto.spec.SecretKeySpec;
import org.sirix.exception.SirixIOException;
@@ -20,17 +22,11 @@
* @author Sebastian Graf, University of Konstanz
*
*/
-public class Encryptor implements ByteHandler {
+public final class Encryptor implements ByteHandler {
/** Algorithm to use. */
private static final String ALGORITHM = "AES";
- /** Iterations. */
- private static final int ITERATIONS = 2;
-
- /** Cipher to perform encryption and decryption operations. */
- private final Cipher mCipher;
-
/** Key for access data. */
private final Key mKey;
@@ -45,50 +41,30 @@
* if an I/O error occurs
*/
public Encryptor() {
- try {
- mCipher = Cipher.getInstance(ALGORITHM);
- mKey = new SecretKeySpec(KEYVALUE, "AES");
- } catch (final NoSuchAlgorithmException e) {
- throw new IllegalStateException(e);
- } catch (final NoSuchPaddingException e) {
- throw new IllegalStateException(e);
- }
+ mKey = new SecretKeySpec(KEYVALUE, ALGORITHM);
}
@Override
- public byte[] serialize(final byte[] toSerialize)
- throws SirixIOException {
+ public OutputStream serialize(final OutputStream toSerialize)
+ throws IOException {
try {
- mCipher.init(Cipher.ENCRYPT_MODE, mKey);
-
- byte[] toEncrypt = toSerialize;
- for (int i = 0; i < ITERATIONS; i++) {
- byte[] encValue = mCipher.doFinal(toEncrypt);
- toEncrypt = encValue;
- }
- return toEncrypt;
+ final Cipher cipher = Cipher.getInstance(ALGORITHM);
+ cipher.init(Cipher.ENCRYPT_MODE, mKey);
+ return new CipherOutputStream(toSerialize, cipher);
} catch (final GeneralSecurityException e) {
- throw new SirixIOException(e);
+ throw new IOException(e);
}
}
@Override
- public byte[] deserialize(final byte[] toDeserialize)
- throws SirixIOException {
+ public InputStream deserialize(final InputStream toDeserialize)
+ throws IOException {
try {
- mCipher.init(Cipher.DECRYPT_MODE, mKey);
-
- byte[] toDecrypt = toDeserialize;
- for (int i = 0; i < ITERATIONS; i++) {
- byte[] decValue = mCipher.doFinal(toDecrypt);
- toDecrypt = decValue;
- }
- return toDecrypt;
-
- } catch (final InvalidKeyException e) {
- throw new SirixIOException(e);
+ final Cipher cipher = Cipher.getInstance(ALGORITHM);
+ cipher.init(Cipher.DECRYPT_MODE, mKey);
+ return new CipherInputStream(toDeserialize, cipher);
} catch (final GeneralSecurityException e) {
- throw new SirixIOException(e);
+ throw new IOException(e);
}
}
View
32 bundles/sirix-core/src/main/java/org/sirix/io/bytepipe/SnappyCompressor.java
@@ -1,9 +1,11 @@
package org.sirix.io.bytepipe;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
-import org.sirix.exception.SirixIOException;
-import org.xerial.snappy.Snappy;
+import org.xerial.snappy.SnappyInputStream;
+import org.xerial.snappy.SnappyOutputStream;
/**
* Snappy compression/decompression.
@@ -11,30 +13,18 @@
* @author Johannes Lichtenberger, University of Konstanz
*
*/
-public class SnappyCompressor implements ByteHandler {
+public final class SnappyCompressor implements ByteHandler {
@Override
- public byte[] serialize(final byte[] toSerialize)
- throws SirixIOException {
- byte[] compressed;
- try {
- compressed = Snappy.compress(toSerialize);
- } catch (final IOException e) {
- throw new SirixIOException(e);
- }
- return compressed;
+ public OutputStream serialize(final OutputStream toSerialize)
+ throws IOException {
+ return new SnappyOutputStream(toSerialize);
}
@Override
- public byte[] deserialize(final byte[] toDeserialize)
- throws SirixIOException {
- byte[] uncompressed;
- try {
- uncompressed = Snappy.uncompress(toDeserialize);
- } catch (final IOException e) {
- throw new SirixIOException(e);
- }
- return uncompressed;
+ public InputStream deserialize(final InputStream toDeserialize)
+ throws IOException {
+ return new SnappyInputStream(toDeserialize);
}
@Override
View
9 bundles/sirix-core/src/main/java/org/sirix/io/file/FileReader.java
@@ -29,6 +29,8 @@
import static com.google.common.base.Preconditions.checkNotNull;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -45,9 +47,6 @@
import org.sirix.page.UberPage;
import org.sirix.page.interfaces.Page;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteStreams;
-
/**
* File Reader. Used for {@link PageReadTrx} to provide read only access on a
* RandomAccessFile.
@@ -107,8 +106,8 @@ public Page read(final @Nonnegative long key, final @Nullable PageReadTrx pageRe
mFile.read(page);
// Perform byte operations.
- final ByteArrayDataInput input = ByteStreams.newDataInput(mByteHandler
- .deserialize(page));
+ final DataInputStream input = new DataInputStream(mByteHandler
+ .deserialize(new ByteArrayInputStream(page)));
// Return reader required to instantiate and deserialize page.
return PagePersistenter.deserializePage(input, pageReadTrx);
View
25 bundles/sirix-core/src/main/java/org/sirix/io/file/FileWriter.java
@@ -27,9 +27,13 @@
package org.sirix.io.file;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
@@ -41,7 +45,6 @@
import org.sirix.page.PageReference;
import org.sirix.page.interfaces.Page;
-import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
/**
@@ -90,16 +93,20 @@ public FileWriter(final File storage,
@Override
public void write(final PageReference pageReference)
throws SirixIOException {
- // Serialise page.
- final Page page = pageReference.getPage();
- assert page != null;
- final ByteArrayDataOutput output = ByteStreams.newDataOutput();
- PagePersistenter.serializePage(output, page);
-
// Perform byte operations.
try {
- final byte[] serializedPage = mReader.mByteHandler.serialize(output
- .toByteArray());
+ // Serialize page.
+ final Page page = pageReference.getPage();
+ assert page != null;
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+ PagePersistenter.serializePage(new DataOutputStream(output), page);
+
+ final OutputStream out = mReader.mByteHandler.serialize(output);
+
+ ByteStreams.copy(new ByteArrayInputStream(output.toByteArray()), out);
+
+ final byte[] serializedPage = output.toByteArray();
final byte[] writtenPage = new byte[serializedPage.length
+ FileReader.OTHER_BEACON];
View
172 bundles/sirix-core/src/main/java/org/sirix/node/Kind.java
@@ -29,8 +29,10 @@
import static org.sirix.node.Utils.getVarLong;
import static org.sirix.node.Utils.putVarLong;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -65,8 +67,6 @@
import com.google.common.base.Optional;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
/**
* Enumeration for different nodes. All nodes are determined by a unique id.
@@ -80,8 +80,8 @@
/** Node kind is element. */
ELEMENT((byte) 1, ElementNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
// Node delegate.
final NodeDelegate nodeDel = deserializeNodeDelegate(source, recordID,
pageReadTrx);
@@ -114,9 +114,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final ElementNode node = (ElementNode) record;
final Node nextNode = (Node) nextRecord;
serializeDelegate(node.getNodeDelegate(), nextNode, sink, pageReadTrx);
@@ -138,8 +138,8 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is attribute. */
ATTRIBUTE((byte) 2, AttributeNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
// Node delegate.
final NodeDelegate nodeDel = deserializeNodeDelegate(source, recordID,
pageReadTrx);
@@ -159,9 +159,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final AttributeNode node = (AttributeNode) record;
final Node nextNode = (Node) nextRecord;
serializeDelegate(node.getNodeDelegate(), nextNode, sink, pageReadTrx);
@@ -173,8 +173,8 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is namespace. */
NAMESPACE((byte) 13, NamespaceNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
// Node delegate.
final NodeDelegate nodeDel = deserializeNodeDelegate(source, recordID,
pageReadTrx);
@@ -186,9 +186,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final NamespaceNode node = (NamespaceNode) record;
final Node nextNode = (Node) nextRecord;
serializeDelegate(node.getNodeDelegate(), nextNode, sink, pageReadTrx);
@@ -199,8 +199,8 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is text. */
TEXT((byte) 3, TextNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
// Node delegate.
final NodeDelegate nodeDel = deserializeNodeDelegate(source, recordID,
pageReadTrx);
@@ -223,9 +223,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final TextNode node = (TextNode) record;
final Node nextNode = (Node) nextRecord;
serializeDelegate(node.getNodeDelegate(), nextNode, sink, pageReadTrx);
@@ -240,8 +240,8 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is processing instruction. */
PROCESSING_INSTRUCTION((byte) 7, PINode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
// Node delegate.
final NodeDelegate nodeDel = deserializeNodeDelegate(source, recordID,
pageReadTrx);
@@ -264,9 +264,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final PINode node = (PINode) record;
final Node nextNode = (Node) nextRecord;
serializeDelegate(node.getNodeDelegate(), nextNode, sink, pageReadTrx);
@@ -279,8 +279,8 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is comment. */
COMMENT((byte) 8, CommentNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
// Node delegate.
final NodeDelegate nodeDel = deserializeNodeDelegate(source, recordID,
pageReadTrx);
@@ -303,9 +303,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final CommentNode node = (CommentNode) record;
final Node nextNode = (Node) nextRecord;
serializeDelegate(node.getNodeDelegate(), nextNode, sink, pageReadTrx);
@@ -321,8 +321,8 @@ public void serialize(final ByteArrayDataOutput sink,
// Virtualize document root node?
DOCUMENT((byte) 9, DocumentRootNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
final NodeDelegate nodeDel = new NodeDelegate(
Fixed.DOCUMENT_NODE_KEY.getStandardProperty(),
Fixed.NULL_NODE_KEY.getStandardProperty(), source.readLong(),
@@ -335,9 +335,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput pSink,
+ public void serialize(final DataOutputStream pSink,
final Record precord, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final DocumentRootNode node = (DocumentRootNode) precord;
pSink.writeLong(node.getHash());
putVarLong(pSink, node.getRevision());
@@ -350,13 +350,13 @@ public void serialize(final ByteArrayDataOutput pSink,
/** Whitespace text. */
WHITESPACE((byte) 4, null) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
@@ -366,7 +366,7 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is deleted node. */
DELETE((byte) 5, DeletedNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
+ public Record deserialize(final DataInputStream source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
final NodeDelegate delegate = new NodeDelegate(recordID, 0, 0, 0,
Optional.<SirixDeweyID> absent());
@@ -374,7 +374,7 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
final PageReadTrx pageReadTrx) {
// DeletedNode node = (DeletedNode) record;
@@ -385,13 +385,13 @@ public void serialize(final ByteArrayDataOutput sink,
/** NullNode to support the Null Object pattern. */
NULL((byte) 6, NullNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
+ public Record deserialize(final DataInputStream source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final ByteArrayDataOutput ink,
+ public void serialize(final DataOutputStream ink,
final Record record, final @Nullable Record nextRecord,
final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
@@ -401,14 +401,14 @@ public void serialize(final ByteArrayDataOutput ink,
/** Dumb node for testing. */
DUMB((byte) 20, DumbNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
+ public Record deserialize(final DataInputStream source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
// final long nodeKey = getVarLong(source);
return new DumbNode(recordID);
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
final PageReadTrx pageReadTrx) {
// putVarLong(sink, record.getNodeKey());
@@ -418,13 +418,13 @@ public void serialize(final ByteArrayDataOutput sink,
/** AtomicKind. */
ATOMIC((byte) 15, AtomicValue.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
+ public Record deserialize(final DataInputStream source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
@@ -434,8 +434,8 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is path node. */
PATH((byte) 16, PathNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
// Node delegate.
final NodeDelegate nodeDel = deserializeNodeDelegateWithoutIDs(source,
recordID, pageReadTrx);
@@ -451,9 +451,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final PathNode node = (PathNode) record;
final Node nextNode = (Node) nextRecord;
serializeDelegate(node.getNodeDelegate(), nextNode, sink, pageReadTrx);
@@ -468,8 +468,8 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node kind is a CAS-AVL node. */
CASAVL((byte) 17, AVLNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
final int valueSize = source.readInt();
final byte[] value = new byte[valueSize];
source.readFully(value, 0, valueSize);
@@ -499,9 +499,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
@SuppressWarnings("unchecked")
final AVLNode<CASValue, NodeReferences> node = (AVLNode<CASValue, NodeReferences>) record;
final CASValue key = node.getKey();
@@ -541,8 +541,8 @@ private Type resolveType(final String s) {
/** Node kind is a PATH-AVL node. */
PATHAVL((byte) 18, AVLNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
final long key = getVarLong(source);
final int keySize = source.readInt();
final Set<Long> nodeKeys = new HashSet<>(keySize);
@@ -564,9 +564,9 @@ public Record deserialize(final ByteArrayDataInput source,
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
@SuppressWarnings("unchecked")
final AVLNode<Long, NodeReferences> node = (AVLNode<Long, NodeReferences>) record;
putVarLong(sink, node.getKey().longValue());
@@ -587,13 +587,13 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node includes a deweyID <=> nodeKey mapping. */
DEWEYIDMAPPING((byte) 23, DeweyIDMappingNode.class) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
+ public Record deserialize(final DataInputStream source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
@@ -603,15 +603,15 @@ public void serialize(final ByteArrayDataOutput sink,
/** Node type not known. */
UNKNOWN((byte) 22, null) {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
throw new UnsupportedOperationException();
}
};
@@ -698,8 +698,8 @@ public static Kind getKind(final Class<? extends Record> clazz) {
* @return {@link NodeDelegate} instance
*/
private static final NodeDelegate deserializeNodeDelegateWithoutIDs(
- final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
final long nodeKey = recordID;
final long parentKey = nodeKey - getVarLong(source);
final long hash = source.readLong();
@@ -718,8 +718,8 @@ private static final NodeDelegate deserializeNodeDelegateWithoutIDs(
* @return {@link NodeDelegate} instance
*/
private static final NodeDelegate deserializeNodeDelegate(
- final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
final long nodeKey = recordID;
final long parentKey = nodeKey - getVarLong(source);
final long hash = source.readLong();
@@ -749,8 +749,8 @@ private static final NodeDelegate deserializeNodeDelegate(
*/
private static final void serializeDelegate(
final NodeDelegate nodeDel, final Node nextNode,
- final ByteArrayDataOutput sink,
- final PageReadTrx pageReadTrx) {
+ final DataOutputStream sink,
+ final PageReadTrx pageReadTrx) throws IOException {
putVarLong(sink, nodeDel.getNodeKey() - nodeDel.getParentKey());
sink.writeLong(nodeDel.getHash());
putVarLong(sink, nodeDel.getRevision());
@@ -786,21 +786,21 @@ private static final void serializeDelegate(
}
}
- /**
- * Write the deweyID.
- *
- * @param sink
- * to write to
- * @param deweyID
- * deweyID in bytes
- * @param i
- * the index from which to start the copy of the array
- */
- private static void writeDeweyID(final ByteArrayDataOutput sink,
- final byte[] deweyID, final @Nonnegative int i) {
- sink.writeByte(deweyID.length - i - 1);
- sink.write(Arrays.copyOfRange(deweyID, i, deweyID.length));
- }
+// /**
+// * Write the deweyID.
+// *
+// * @param sink
+// * to write to
+// * @param deweyID
+// * deweyID in bytes
+// * @param i
+// * the index from which to start the copy of the array
+// */
+// private static void writeDeweyID(final DataOutputStream sink,
+// final byte[] deweyID, final @Nonnegative int i) throws IOException {
+// sink.writeByte(deweyID.length - i - 1);
+// sink.write(Arrays.copyOfRange(deweyID, i, deweyID.length));
+// }
/**
* Serializing the {@link StructNodeDelegate} instance.
@@ -812,7 +812,7 @@ private static void writeDeweyID(final ByteArrayDataOutput sink,
*/
private static final void serializeStrucDelegate(
final StructNodeDelegate nodeDel,
- final ByteArrayDataOutput sink) {
+ final DataOutputStream sink) throws IOException {
putVarLong(sink, nodeDel.getNodeKey() - nodeDel.getRightSiblingKey());
putVarLong(sink, nodeDel.getNodeKey() - nodeDel.getLeftSiblingKey());
putVarLong(sink, nodeDel.getNodeKey() - nodeDel.getFirstChildKey());
@@ -831,7 +831,7 @@ private static final void serializeStrucDelegate(
*/
private static final StructNodeDelegate deserializeStructDel(
final NodeDelegate nodeDel,
- final ByteArrayDataInput source) {
+ final DataInputStream source) throws IOException {
final long currKey = nodeDel.getNodeKey();
final long rightSibl = currKey - getVarLong(source);
final long leftSibl = currKey - getVarLong(source);
@@ -853,7 +853,7 @@ private static final StructNodeDelegate deserializeStructDel(
*/
private static final NameNodeDelegate deserializeNameDelegate(
final NodeDelegate nodeDel,
- final ByteArrayDataInput source) {
+ final DataInputStream source) throws IOException {
final int uriKey = source.readInt();
int prefixKey = source.readInt();
int localNameKey = source.readInt();
@@ -871,7 +871,7 @@ private static final NameNodeDelegate deserializeNameDelegate(
*/
private static final void serializeNameDelegate(
final NameNodeDelegate nameDel,
- final ByteArrayDataOutput sink) {
+ final DataOutputStream sink) throws IOException {
sink.writeInt(nameDel.getURIKey());
sink.writeInt(nameDel.getPrefixKey());
sink.writeInt(nameDel.getLocalNameKey());
@@ -888,7 +888,7 @@ private static final void serializeNameDelegate(
*/
private static final void serializeValDelegate(
final ValNodeDelegate valueDel,
- final ByteArrayDataOutput sink) {
+ final DataOutputStream sink) throws IOException {
final boolean isCompressed = valueDel.isCompressed();
sink.writeByte(isCompressed ? (byte) 1 : (byte) 0);
final byte[] value = isCompressed ? valueDel.getCompressed() : valueDel
View
15 bundles/sirix-core/src/main/java/org/sirix/node/NodePersistenter.java
@@ -1,5 +1,9 @@
package org.sirix.node;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import javax.annotation.Nonnegative;
import javax.annotation.Nullable;
@@ -7,9 +11,6 @@
import org.sirix.node.interfaces.Record;
import org.sirix.node.interfaces.RecordPersistenter;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-
/**
* Persist nodes.
*
@@ -18,17 +19,17 @@
*/
public final class NodePersistenter implements RecordPersistenter {
@Override
- public Record deserialize(final ByteArrayDataInput source,
- final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
+ public Record deserialize(final DataInputStream source,
+ final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
final byte id = source.readByte();
final Kind enumKind = Kind.getKind(id);
return enumKind.deserialize(source, recordID, pageReadTrx);
}
@Override
- public void serialize(final ByteArrayDataOutput sink,
+ public void serialize(final DataOutputStream sink,
final Record record, final @Nullable Record nextRecord,
- final PageReadTrx pageReadTrx) {
+ final PageReadTrx pageReadTrx) throws IOException {
final Kind nodeKind = (Kind) record.getKind();
final byte id = nodeKind.getId();
sink.writeByte(id);
View
8 bundles/sirix-core/src/main/java/org/sirix/node/Utils.java
@@ -1,5 +1,9 @@
package org.sirix.node;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
@@ -14,7 +18,7 @@
* long value
*/
public static final void putVarLong(
- final ByteArrayDataOutput output, long value) {
+ final DataOutputStream output, long value) throws IOException {
while ((value & ~0x7F) != 0) {
output.write(((byte) ((value & 0x7f) | 0x80)));
value >>>= 7;
@@ -29,7 +33,7 @@ public static final void putVarLong(
* {@link ByteArrayDataInput} reference
* @return long value
*/
- public static final long getVarLong(final ByteArrayDataInput input) {
+ public static final long getVarLong(final DataInputStream input) throws IOException {
byte singleByte = input.readByte();
long value = singleByte & 0x7F;
for (int shift = 7; (singleByte & 0x80) != 0; shift += 7) {
View
16 bundles/sirix-core/src/main/java/org/sirix/node/interfaces/RecordPersistenter.java
@@ -1,5 +1,9 @@
package org.sirix.node.interfaces;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
@@ -27,10 +31,12 @@
* @return a {@link Node} instance
* @throws NullPointerException
* if one of the parameters is {@code null}
+ * @throws IOException
+ * if an I/O error occurs during deserialization
*/
@Nonnull
- Record deserialize(ByteArrayDataInput source, @Nonnegative long recordID,
- @Nonnull PageReadTrx pageReadTrx);
+ Record deserialize(DataInputStream source, @Nonnegative long recordID,
+ @Nonnull PageReadTrx pageReadTrx) throws IOException;
/**
* Serialize a record from a {@link ByteArrayDataOutput} instance.
@@ -46,7 +52,9 @@ Record deserialize(ByteArrayDataInput source, @Nonnegative long recordID,
* {@link PageReadTrx} instance
* @throws NullPointerException
* if one of the parameters is {@code null}
+ * @throws IOException
+ * if an I/O error occurs during serialization
*/
- void serialize(ByteArrayDataOutput sink, @Nonnull Record record,
- @Nonnull Record previousRecord, @Nonnull PageReadTrx pageReadTrx);
+ void serialize(DataOutputStream sink, @Nonnull Record record,
+ @Nonnull Record previousRecord, @Nonnull PageReadTrx pageReadTrx) throws IOException;
}
View
6 bundles/sirix-core/src/main/java/org/sirix/page/AbstractForwardingPage.java
@@ -28,6 +28,9 @@
import static com.google.common.base.Preconditions.checkNotNull;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import javax.annotation.Nonnegative;
import org.sirix.api.PageWriteTrx;
@@ -37,7 +40,6 @@
import org.sirix.page.interfaces.Page;
import com.google.common.collect.ForwardingObject;
-import com.google.common.io.ByteArrayDataOutput;
/**
* Forwarding the implementation of all methods in the {@link Page} interface to
@@ -73,7 +75,7 @@ public PageReference getReference(final @Nonnegative int offset) {
}
@Override
- public void serialize(final ByteArrayDataOutput out) {
+ public void serialize(final DataOutputStream out) throws IOException {
delegate().serialize(checkNotNull(out));
}
View
9 bundles/sirix-core/src/main/java/org/sirix/page/CASPage.java
@@ -26,6 +26,9 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -38,8 +41,6 @@
import org.sirix.settings.Constants;
import com.google.common.base.Objects;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
/**
* Page to hold references to a content and value summary.
@@ -80,7 +81,7 @@ public PageReference getIndirectPageReference(int index) {
* @param in
* input bytes to read from
*/
- protected CASPage(final ByteArrayDataInput in) {
+ protected CASPage(final DataInputStream in) throws IOException {
mDelegate = new PageDelegate(PageConstants.MAX_INDEX_NR, in);
final int size = in.readInt();
mMaxNodeKeys = new HashMap<>(size);
@@ -128,7 +129,7 @@ public Page setDirty(final boolean pDirty) {
}
@Override
- public void serialize(ByteArrayDataOutput out) {
+ public void serialize(DataOutputStream out) throws IOException {
super.serialize(out);
final int size = mMaxNodeKeys.size();
out.writeInt(size);
View
7 bundles/sirix-core/src/main/java/org/sirix/page/IndirectPage.java
@@ -27,12 +27,13 @@
package org.sirix.page;
+import java.io.DataInputStream;
+import java.io.IOException;
+
import org.sirix.page.delegates.PageDelegate;
import org.sirix.page.interfaces.Page;
import org.sirix.settings.Constants;
-import com.google.common.io.ByteArrayDataInput;
-
/**
* <h1>IndirectPage</h1>
*
@@ -59,7 +60,7 @@ public IndirectPage() {
* @param in
* input source
*/
- protected IndirectPage(final ByteArrayDataInput in) {
+ protected IndirectPage(final DataInputStream in) throws IOException {
mDelegate = new PageDelegate(Constants.INP_REFERENCE_COUNT, in);
}
View
9 bundles/sirix-core/src/main/java/org/sirix/page/NamePage.java
@@ -27,6 +27,9 @@
package org.sirix.page;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -43,8 +46,6 @@
import org.sirix.settings.Constants;
import com.google.common.base.Objects;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
/**
* <h1>NamePage</h1>
@@ -91,7 +92,7 @@ public NamePage() {
* @param in
* input bytes to read from
*/
- protected NamePage(final ByteArrayDataInput in) {
+ protected NamePage(final DataInputStream in) throws IOException {
mDelegate = new PageDelegate(PageConstants.MAX_INDEX_NR, in);
final int size = in.readInt();
mMaxNodeKeys = new HashMap<>(size);
@@ -219,7 +220,7 @@ public void setName(final int key, final String name,
}
@Override
- public void serialize(final ByteArrayDataOutput out) {
+ public void serialize(DataOutputStream out) throws IOException {
super.serialize(out);
final int size = mMaxNodeKeys.size();
out.writeInt(size);
View
11 bundles/sirix-core/src/main/java/org/sirix/page/OverflowPage.java
@@ -1,14 +1,15 @@
package org.sirix.page;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import org.sirix.api.PageWriteTrx;
import org.sirix.exception.SirixException;
import org.sirix.node.interfaces.Record;
import org.sirix.page.interfaces.KeyValuePage;
import org.sirix.page.interfaces.Page;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-
/**
* OverflowPage used to store records which are longer than a predefined
* threshold.
@@ -40,7 +41,7 @@ public OverflowPage(final byte[] data) {
mData = data;
}
- public OverflowPage(final ByteArrayDataInput in) {
+ public OverflowPage(final DataInputStream in) throws IOException {
mData = new byte[in.readInt()];
in.readFully(mData);
}
@@ -72,7 +73,7 @@ public Page setDirty(final boolean dirty) {
}
@Override
- public void serialize(final ByteArrayDataOutput out) {
+ public void serialize(final DataOutputStream out) throws IOException {
out.writeInt(mData.length);
out.write(mData);
}
View
96 bundles/sirix-core/src/main/java/org/sirix/page/PageKind.java
@@ -26,6 +26,9 @@
*/
package org.sirix.page;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -34,9 +37,6 @@
import org.sirix.api.PageReadTrx;
import org.sirix.page.interfaces.Page;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-
/**
* All Page types.
*/
@@ -47,14 +47,14 @@
RECORDPAGE((byte) 1, UnorderedKeyValuePage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new UnorderedKeyValuePage(source, pageReadTrx);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(RECORDPAGE.mId);
page.serialize(sink);
}
@@ -76,14 +76,14 @@ Page getInstance(final Page nodePage,
NAMEPAGE((byte) 2, NamePage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new NamePage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(NAMEPAGE.mId);
page.serialize(sink);
}
@@ -102,14 +102,14 @@ Page getInstance(final Page page,
UBERPAGE((byte) 3, UberPage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new UberPage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(UBERPAGE.mId);
page.serialize(sink);
}
@@ -128,14 +128,14 @@ Page getInstance(final Page page,
INDIRECTPAGE((byte) 4, IndirectPage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new IndirectPage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(INDIRECTPAGE.mId);
page.serialize(sink);
}
@@ -154,14 +154,14 @@ Page getInstance(final Page page,
REVISIONROOTPAGE((byte) 5, RevisionRootPage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new RevisionRootPage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(REVISIONROOTPAGE.mId);
page.serialize(sink);
}
@@ -180,14 +180,14 @@ Page getInstance(final Page page,
PATHSUMMARYPAGE((byte) 6, PathSummaryPage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new PathSummaryPage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(PATHSUMMARYPAGE.mId);
page.serialize(sink);
}
@@ -206,14 +206,14 @@ Page getInstance(final Page page,
TEXTVALUEPAGE((byte) 7, PathPage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new PathPage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(TEXTVALUEPAGE.mId);
page.serialize(sink);
}
@@ -232,14 +232,14 @@ Page getInstance(final Page page,
CASPAGE((byte) 8, CASPage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException{
return new CASPage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(CASPAGE.mId);
page.serialize(sink);
}
@@ -258,14 +258,14 @@ Page getInstance(final Page page,
OVERFLOWPAGE((byte) 9, OverflowPage.class) {
@Override
@Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return new OverflowPage(source);
}
@Override
- void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
sink.writeByte(OVERFLOWPAGE.mId);
page.serialize(sink);
}
@@ -283,14 +283,14 @@ Page getInstance(final Page page,
*/
PATHPAGE((byte) 10, PathPage.class) {
@Override
- void serializePage(ByteArrayDataOutput sink, @Nonnull Page page) {
+ void serializePage(DataOutputStream sink, @Nonnull Page page) throws IOException {
sink.writeByte(PATHPAGE.mId);
page.serialize(sink);
}
@Override
- Page deserializePage(ByteArrayDataInput source,
- @Nonnull PageReadTrx pageReadTrx) {
+ Page deserializePage(DataInputStream source,
+ @Nonnull PageReadTrx pageReadTrx) throws IOException {
return new PathPage(source);
}
@@ -347,24 +347,24 @@ public byte getID() {
* Serialize page.
*
* @param sink
- * {@link ByteArrayDataInput} instance
+ * {@link DataInputStream} instance
* @param page
* {@link Page} implementation
*/
- abstract void serializePage(final ByteArrayDataOutput sink,
- final Page page);
+ abstract void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException;
/**
* Deserialize page.
*
* @param source
- * {@link ByteArrayDataInput} instance
+ * {@link DataInputStream} instance
* @param pageReadTrx
* implementing {@link PageReadTrx} instance
* @return page instance implementing the {@link Page} interface
*/
- abstract Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx);
+ abstract Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException;
/**
* Public method to get the related page based on the identifier.
View
19 bundles/sirix-core/src/main/java/org/sirix/page/PagePersistenter.java
@@ -27,14 +27,15 @@
package org.sirix.page;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
import javax.annotation.Nonnull;
import org.sirix.api.PageReadTrx;
import org.sirix.page.interfaces.Page;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-
/**
* Persists pages on secondary storage.
*
@@ -52,10 +53,12 @@
* instance of class, which implements the {@link PageReadTrx}
* interface
* @return {@link Page} instance
+ * @throws IOException
+ * if an exception during deserialization of a page occurs
*/
public static @Nonnull
- Page deserializePage(final ByteArrayDataInput source,
- final PageReadTrx pageReadTrx) {
+ Page deserializePage(final DataInputStream source,
+ final PageReadTrx pageReadTrx) throws IOException {
return PageKind.getKind(source.readByte()).deserializePage(source,
pageReadTrx);
}
@@ -67,9 +70,11 @@ Page deserializePage(final ByteArrayDataInput source,
* output sink
* @param page
* the {@link Page} to serialize
+ * @throws IOException
+ * if an exception during serialization of a page occurs
*/
- public static void serializePage(final ByteArrayDataOutput sink,
- final Page page) {
+ public static void serializePage(final DataOutputStream sink,
+ final Page page) throws IOException {
PageKind.getKind(page.getClass()).serializePage(sink, page);
}
View
11 bundles/sirix-core/src/main/java/org/sirix/page/PathPage.java
@@ -26,6 +26,9 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.util.HashMap;