Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-25 10:59:43 +0000
committerEike Stepper2007-08-25 10:59:43 +0000
commitdebd33662d508aa7a5136fc9e651c3ac8175a1e8 (patch)
treeb3ba7851af0bbbdf8a0720acde354de2a53dc2de /plugins/org.eclipse.net4j.tests
parentd2a5fd4bfbef792c4aba6c8d0311ebef2f8036d9 (diff)
downloadcdo-debd33662d508aa7a5136fc9e651c3ac8175a1e8.tar.gz
cdo-debd33662d508aa7a5136fc9e651c3ac8175a1e8.tar.xz
cdo-debd33662d508aa7a5136fc9e651c3ac8175a1e8.zip
*** empty log message ***
Diffstat (limited to 'plugins/org.eclipse.net4j.tests')
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java
new file mode 100644
index 0000000000..08b91511a1
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java
@@ -0,0 +1,98 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.io.ExtendedIOUtil;
+import org.eclipse.net4j.util.io.SortedFileMap;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class SortedFileMapTest extends AbstractOMTest
+{
+ public void testMap() throws Exception
+ {
+ File file = new File("SortedFileMapTest.dat");
+ SortedFileMap<Integer, String> map = new TestMap(file);
+
+ try
+ {
+ map.put(1, "Eike");
+ map.put(3, "René");
+ map.put(7, "Birte");
+ map.put(9, "Mama");
+ map.put(11, "Papa");
+ map.put(15, "Julchen");
+ }
+ finally
+ {
+ map.close();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TestMap extends SortedFileMap<Integer, String>
+ {
+ public TestMap(File file)
+ {
+ super(file, "rw");
+ }
+
+ @Override
+ public int getKeySize()
+ {
+ return 4;
+ }
+
+ @Override
+ protected Integer readKey(DataInput in) throws IOException
+ {
+ return in.readInt();
+ }
+
+ @Override
+ protected void writeKey(DataOutput out, Integer key) throws IOException
+ {
+ out.writeInt(key);
+ }
+
+ @Override
+ public int getValueSize()
+ {
+ return 20;
+ }
+
+ @Override
+ protected String readValue(DataInput in) throws IOException
+ {
+ return ExtendedIOUtil.readString(in);
+ }
+
+ @Override
+ protected void writeValue(DataOutput out, String value) throws IOException
+ {
+ byte[] bytes = value.getBytes();
+ if (bytes.length + 4 > getValueSize())
+ {
+ throw new IllegalArgumentException("Value size of " + getValueSize() + " exceeded: " + value);
+ }
+
+ ExtendedIOUtil.writeByteArray(out, bytes);
+ }
+ }
+}

Back to the top