harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [123/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/WeakHashMap.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/WeakHashMap.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/WeakHashMap.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/util/WeakHashMap.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,615 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+/**
+ * WeakHashMap is an implementation of Map with keys which are WeakReferences.
+ * The key/value mapping is removed when the key is no longer referenced. All
+ * optional operations are supported, adding and removing. Keys and values can
+ * be any objects.
+ */
+public class WeakHashMap extends AbstractMap implements Map {
+	
+	private ReferenceQueue referenceQueue;
+
+	int elementCount;
+
+	WeakHashMapEntry[] elementData;
+
+	private int loadFactor;
+
+	private int threshold;
+
+	transient int modCount = 0;
+
+	private static final int DEFAULT_SIZE = 16;
+
+	private static final class WeakHashMapEntry extends WeakReference {
+		int hash;
+
+		boolean isNull;
+
+		Object value;
+
+		WeakHashMapEntry next;
+
+		private WeakHashMapEntry(Object key, Object object, ReferenceQueue queue) {
+			super(key, queue);
+			isNull = key == null;
+			hash = isNull ? 0 : key.hashCode();
+			value = object;
+		}
+	}
+
+	private static final class KeyEntry implements Map.Entry {
+		private Object key;
+
+		private WeakHashMapEntry entry;
+
+		interface Type {
+			Object get(KeyEntry entry);
+		}
+
+		KeyEntry(Object key, WeakHashMapEntry entry) {
+			this.key = key;
+			this.entry = entry;
+		}
+
+		public Object getKey() {
+			return key;
+		}
+
+		public Object getValue() {
+			return entry.value;
+		}
+
+		public Object setValue(Object object) {
+			Object result = entry.value;
+			entry.value = object;
+			return result;
+		}
+	}
+
+	class HashIterator implements Iterator {
+		private int position = 0, expectedModCount;
+
+		private boolean canRemove = false;
+
+		private WeakHashMapEntry entry, lastEntry;
+
+		private KeyEntry next;
+
+		KeyEntry.Type type;
+
+		HashIterator(KeyEntry.Type type, WeakHashMap map) {
+			this.type = type;
+			expectedModCount = modCount;
+		}
+
+		public boolean hasNext() {
+			if (next != null)
+				return true;
+			while (true) {
+				if (entry == null) {
+					lastEntry = null;
+					while (position < elementData.length)
+						if ((entry = elementData[position++]) != null)
+							break;
+					if (entry == null)
+						return false;
+				}
+				Object key = entry.get();
+				if (key != null || entry.isNull) {
+					next = new KeyEntry(key, entry);
+					return true;
+				}
+				entry = entry.next;
+			}
+		}
+
+		public Object next() {
+			if (expectedModCount == modCount) {
+				if (hasNext()) {
+					if (lastEntry == null)
+						lastEntry = entry;
+					else if (lastEntry.next != entry)
+						lastEntry = lastEntry.next;
+					entry = entry.next;
+					canRemove = true;
+					KeyEntry result = next;
+					next = null;
+					return type.get(result);
+				} else
+					throw new NoSuchElementException();
+			} else
+				throw new ConcurrentModificationException();
+		}
+
+		public void remove() {
+			if (expectedModCount == modCount) {
+				if (canRemove) {
+					canRemove = false;
+					modCount++;
+					if (lastEntry.next == entry) {
+						while (elementData[--position] == null) {
+							// do nothing
+						}
+						elementData[position] = elementData[position].next;
+						entry = null;
+					} else
+						lastEntry.next = entry;
+					elementCount--;
+					expectedModCount++;
+					poll();
+				} else
+					throw new IllegalStateException();
+			} else
+				throw new ConcurrentModificationException();
+		}
+	}
+
+	/**
+	 * Contructs a new empty instance of WeakHashMap.
+	 */
+	public WeakHashMap() {
+		this(DEFAULT_SIZE);
+	}
+
+	/**
+	 * Constructs a new instance of WeakHashMap with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            the initial capacity of this WeakHashMap
+	 * 
+	 * @exception IllegalArgumentException
+	 *                when the capacity is less than zero
+	 */
+	public WeakHashMap(int capacity) {
+		if (capacity >= 0) {
+			elementCount = 0;
+			elementData = new WeakHashMapEntry[capacity == 0 ? 1 : capacity];
+			loadFactor = 7500; // Default load factor of 0.75
+			computeMaxSize();
+			referenceQueue = new ReferenceQueue();
+		} else
+			throw new IllegalArgumentException();
+	}
+
+	/**
+	 * Constructs a new instance of WeakHashMap with the specified capacity and
+	 * load factor.
+	 * 
+	 * @param capacity
+	 *            the initial capacity
+	 * @param loadFactor
+	 *            the initial load factor
+	 * 
+	 * @exception IllegalArgumentException
+	 *                when the capacity is less than zero or the load factor is
+	 *                less or equal to zero
+	 */
+	public WeakHashMap(int capacity, float loadFactor) {
+		if (capacity >= 0 && loadFactor > 0) {
+			elementCount = 0;
+			elementData = new WeakHashMapEntry[capacity == 0 ? 1 : capacity];
+			this.loadFactor = (int) (loadFactor * 10000);
+			computeMaxSize();
+			referenceQueue = new ReferenceQueue();
+		} else
+			throw new IllegalArgumentException();
+	}
+
+	/**
+	 * Constructs a new instance of HashMap containing the mappings from the
+	 * specified Map.
+	 * 
+	 * @param map
+	 *            the mappings to add
+	 */
+	public WeakHashMap(Map map) {
+		this(map.size() < 6 ? 11 : map.size() * 2);
+		putAll(map);
+	}
+
+	/**
+	 * Removes all mappings from this WeakHashMap, leaving it empty.
+	 * 
+	 * @see #isEmpty
+	 * @see #size
+	 */
+	public void clear() {
+		if (elementCount > 0) {
+			elementCount = 0;
+			Arrays.fill(elementData, null);
+			modCount++;
+			while (referenceQueue.poll() != null) {
+				// do nothing
+			}
+		}
+	}
+
+	private void computeMaxSize() {
+		threshold = (int) ((long) elementData.length * loadFactor / 10000);
+	}
+
+	/**
+	 * Searches this WeakHashMap for the specified key.
+	 * 
+	 * @param key
+	 *            the object to search for
+	 * @return true if <code>key</code> is a key of this WeakHashMap, false
+	 *         otherwise
+	 */
+	public boolean containsKey(Object key) {
+		return getEntry(key) != null;
+	}
+
+	/**
+	 * Answers a Set of the mappings contained in this WeakHashMap. Each element
+	 * in the set is a Map.Entry. The set is backed by this WeakHashMap so
+	 * changes to one are relected by the other. The set does not support
+	 * adding.
+	 * 
+	 * @return a Set of the mappings
+	 */
+	public Set entrySet() {
+		return new AbstractSet() {
+			public int size() {
+				return WeakHashMap.this.size();
+			}
+
+			public void clear() {
+				WeakHashMap.this.clear();
+			}
+
+			public boolean remove(Object object) {
+				if (contains(object)) {
+					WeakHashMap.this.remove(((Map.Entry) object).getKey());
+					return true;
+				}
+				return false;
+			}
+
+			public boolean contains(Object object) {
+				if (object instanceof Map.Entry) {
+					WeakHashMapEntry entry = getEntry(((Map.Entry) object)
+							.getKey());
+					return object.equals(entry);
+				}
+				return false;
+			}
+
+			public Iterator iterator() {
+				return new HashIterator(new KeyEntry.Type() {
+					public Object get(KeyEntry entry) {
+						return entry;
+					}
+				}, WeakHashMap.this);
+			}
+		};
+	}
+
+	/**
+	 * Answers a Set of the keys contained in this WeakHashMap. The set is
+	 * backed by this WeakHashMap so changes to one are reflected by the other.
+	 * The set does not support adding.
+	 * 
+	 * @return a Set of the keys
+	 */
+	public Set keySet() {
+		if (keySet == null) {
+			keySet = new AbstractSet() {
+				public boolean contains(Object object) {
+					return containsKey(object);
+				}
+
+				public int size() {
+					return WeakHashMap.this.size();
+				}
+
+				public void clear() {
+					WeakHashMap.this.clear();
+				}
+
+				public boolean remove(Object key) {
+					if (containsKey(key)) {
+						WeakHashMap.this.remove(key);
+						return true;
+					}
+					return false;
+				}
+
+				public Iterator iterator() {
+					return new HashIterator(new KeyEntry.Type() {
+						public Object get(KeyEntry entry) {
+							return entry.getKey();
+						}
+					}, WeakHashMap.this);
+				}
+			};
+		}
+		return keySet;
+	}
+
+	/**
+	 * Answers a Collection of the values contained in this WeakHashMap. The
+	 * collection is backed by this WeakHashMap so changes to one are reflected
+	 * by the other. The collection does not support adding.
+	 * 
+	 * @return a Collection of the values
+	 */
+	public Collection values() {
+		if (valuesCollection == null) {
+			valuesCollection = new AbstractCollection() {
+				public int size() {
+					return WeakHashMap.this.size();
+				}
+
+				public void clear() {
+					WeakHashMap.this.clear();
+				}
+
+				public boolean contains(Object object) {
+					return containsValue(object);
+				}
+
+				public Iterator iterator() {
+					return new HashIterator(new KeyEntry.Type() {
+						public Object get(KeyEntry entry) {
+							return entry.getValue();
+						}
+					}, WeakHashMap.this);
+				}
+			};
+		}
+		return valuesCollection;
+	}
+
+	/**
+	 * Answers the value of the mapping with the specified key.
+	 * 
+	 * @param key
+	 *            the key
+	 * @return the value of the mapping with the specified key
+	 */
+	public Object get(Object key) {
+		if (key != null) {
+			int index = (key.hashCode() & 0x7FFFFFFF) % elementData.length;
+			WeakHashMapEntry entry = elementData[index];
+			while (entry != null) {
+				if (key.equals(entry.get()))
+					return entry.value;
+				entry = entry.next;
+			}
+			return null;
+		}
+		WeakHashMapEntry entry = elementData[0];
+		while (entry != null) {
+			if (entry.isNull)
+				return entry.value;
+			entry = entry.next;
+		}
+		return null;
+	}
+
+	WeakHashMapEntry getEntry(Object key) {
+		if (key != null) {
+			int index = (key.hashCode() & 0x7FFFFFFF) % elementData.length;
+			WeakHashMapEntry entry = elementData[index];
+			while (entry != null) {
+				if (key.equals(entry.get()))
+					return entry;
+				entry = entry.next;
+			}
+			return null;
+		}
+		WeakHashMapEntry entry = elementData[0];
+		while (entry != null) {
+			if (entry.isNull)
+				return entry;
+			entry = entry.next;
+		}
+		return null;
+	}
+
+	/**
+	 * Searches this WeakHashMap for the specified value, and returns true, if
+	 * at least one entry has this object as its value.
+	 * 
+	 * @param value
+	 *            the object to search for
+	 * @return true if <code>value</code> is a value in this WeakHashMap,
+	 *         false otherwise
+	 */
+	public boolean containsValue(Object value) {
+		if (value != null) {
+			for (int i = elementData.length; --i >= 0;) {
+				WeakHashMapEntry entry = elementData[i];
+				while (entry != null) {
+					if (value.equals(entry.value))
+						return true;
+					entry = entry.next;
+				}
+			}
+		} else {
+			for (int i = elementData.length; --i >= 0;) {
+				WeakHashMapEntry entry = elementData[i];
+				while (entry != null) {
+					if (entry.value == null)
+						return true;
+					entry = entry.next;
+				}
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * Answers if this WeakHashMap has no elements, a size of zero.
+	 * 
+	 * @return true if this HashMap has no elements, false otherwise
+	 * 
+	 * @see #size
+	 */
+	public boolean isEmpty() {
+		return size() == 0;
+	}
+
+	void poll() {
+		WeakHashMapEntry toRemove;
+		while ((toRemove = (WeakHashMapEntry) referenceQueue.poll()) != null) {
+			WeakHashMapEntry entry, last = null;
+			int index = (toRemove.hash & 0x7FFFFFFF) % elementData.length;
+			entry = elementData[index];
+			// Ignore queued entries which cannot be found, the user could
+			// have removed them before they were queued, i.e. using clear()
+			while (entry != null) {
+				if (toRemove == entry) {
+					modCount++;
+					if (last == null)
+						elementData[index] = entry.next;
+					else
+						last.next = entry.next;
+					elementCount--;
+					break;
+				}
+				last = entry;
+				entry = entry.next;
+			}
+		}
+	}
+
+	/**
+	 * Maps the specified key to the specified value.
+	 * 
+	 * @param key
+	 *            the key
+	 * @param value
+	 *            the value
+	 * @return the value of any previous mapping with the specified key or null
+	 *         if there was no mapping
+	 */
+	public Object put(Object key, Object value) {
+		poll();
+		int index = 0;
+		WeakHashMapEntry entry;
+		if (key != null) {
+			index = (key.hashCode() & 0x7FFFFFFF) % elementData.length;
+			entry = elementData[index];
+			while (entry != null && !key.equals(entry.get()))
+				entry = entry.next;
+		} else {
+			entry = elementData[0];
+			while (entry != null && !entry.isNull)
+				entry = entry.next;
+		}
+		if (entry == null) {
+			modCount++;
+			if (++elementCount > threshold) {
+				rehash();
+				index = key == null ? 0 : (key.hashCode() & 0x7FFFFFFF)
+						% elementData.length;
+			}
+			entry = new WeakHashMapEntry(key, value, referenceQueue);
+			entry.next = elementData[index];
+			elementData[index] = entry;
+			return null;
+		}
+		Object result = entry.value;
+		entry.value = value;
+		return result;
+	}
+
+	private void rehash() {
+		int length = elementData.length << 1;
+		if (length == 0)
+			length = 1;
+		WeakHashMapEntry[] newData = new WeakHashMapEntry[length];
+		for (int i = 0; i < elementData.length; i++) {
+			WeakHashMapEntry entry = elementData[i];
+			while (entry != null) {
+				int index = entry.isNull ? 0 : (entry.hash & 0x7FFFFFFF)
+						% length;
+				WeakHashMapEntry next = entry.next;
+				entry.next = newData[index];
+				newData[index] = entry;
+				entry = next;
+			}
+		}
+		elementData = newData;
+		computeMaxSize();
+	}
+
+	/**
+	 * Removes a mapping with the specified key from this WeakHashMap.
+	 * 
+	 * @param key
+	 *            the key of the mapping to remove
+	 * @return the value of the removed mapping or null if key is not a key in
+	 *         this WeakHashMap
+	 */
+	public Object remove(Object key) {
+		poll();
+		int index = 0;
+		WeakHashMapEntry entry, last = null;
+		if (key != null) {
+			index = (key.hashCode() & 0x7FFFFFFF) % elementData.length;
+			entry = elementData[index];
+			while (entry != null && !key.equals(entry.get())) {
+				last = entry;
+				entry = entry.next;
+			}
+		} else {
+			entry = elementData[0];
+			while (entry != null && !entry.isNull) {
+				last = entry;
+				entry = entry.next;
+			}
+		}
+		if (entry != null) {
+			modCount++;
+			if (last == null)
+				elementData[index] = entry.next;
+			else
+				last.next = entry.next;
+			elementCount--;
+			return entry.value;
+		}
+		return null;
+	}
+
+	/**
+	 * Answers the number of mappings in this WeakHashMap.
+	 * 
+	 * @return the number of mappings in this WeakHashMap
+	 */
+	public int size() {
+		int size = 0;
+		for (int i = elementData.length; --i >= 0;) {
+			WeakHashMapEntry entry = elementData[i];
+			while (entry != null) {
+				if (entry.get() != null || entry.isNull)
+					size++;
+				entry = entry.next;
+			}
+		}
+		return size;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/META-INF/MANIFEST.MF?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/META-INF/MANIFEST.MF (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/META-INF/MANIFEST.MF Wed Nov 30 21:29:27 2005
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Harmony Math
+Bundle-SymbolicName: org.apache.harmony.math
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .
+Eclipse-JREBundle: true
+Export-Package: java.math
+Import-Package: java.util
+Require-Bundle: org.apache.harmony.luni

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigDecimal.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigDecimal.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigDecimal.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigDecimal.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,371 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.math;
+
+/**
+ * BigDecimal objects represent an arbitrary precisioned decimal Number. They
+ * contain values that cannot be changed. Thus, most operations on the
+ * BigDecimal object yield new instances of BigDecimal.
+ * <p>
+ * BigDecimal is respresented by an unscaled BigInteger value and an integer
+ * representing the scale of the object. The scale of the BigDecimal is the
+ * number of digits after the decimal point. Eg. 1.234 would have a scale of 3
+ * and an unscaled value of 1234. Therefore, decimal representation of a
+ * BigDecimal is BigIntegerValue/10^scale.
+ * 
+ * @see java.math.BigInteger
+ */
+public class BigDecimal extends Number implements Comparable {
+
+	static final long serialVersionUID = 6108874887143696463L;
+
+	/**
+	 * Rounding mode Constants
+	 */
+	public final static int ROUND_UP = 0;
+
+	public final static int ROUND_DOWN = 1;
+
+	public final static int ROUND_CEILING = 2;
+
+	public final static int ROUND_FLOOR = 3;
+
+	public final static int ROUND_HALF_UP = 4;
+
+	public final static int ROUND_HALF_DOWN = 5;
+
+	public final static int ROUND_HALF_EVEN = 6;
+
+	public final static int ROUND_UNNECESSARY = 7;
+
+	/**
+	 * Constructs a BigDecimal with unscaled value initialized as bval and scale
+	 * as 0.
+	 */
+	public BigDecimal(BigInteger bval) {
+	}
+
+	/**
+	 * Constructs a BigDecimal with unscaled value initialized as bval and scale
+	 * as scale from the argument.
+	 */
+	public BigDecimal(BigInteger bval, int sc) {
+	}
+
+	/**
+	 * Constructs a BigDecimal with a double value as an arugment.
+	 * 
+	 * @exception NumberFormatException
+	 *                If the is Infinity, Negative Infinity or NaN.
+	 */
+	public BigDecimal(double bval) {
+	}
+
+	/**
+	 * Constructs a BigDecimal from the strong which can only contan digits of
+	 * 0-9, a decimal point and a negative sign.
+	 * 
+	 * @exception NumberFormatException
+	 *                If the argument contained characters other than digits.
+	 */
+	public BigDecimal(String bval) {
+	}
+
+	/**
+	 * Answers the absolute value of this BigDecimal.
+	 * 
+	 * @return BigDecimal absolute value of the receiver.
+	 */
+	public BigDecimal abs() {
+		return null;
+	}
+
+	/**
+	 * Answers the sum of the receiver and argument.
+	 * 
+	 * @return BigDecimal The sum of adding two BigDecimal.
+	 */
+	public BigDecimal add(BigDecimal bval) {
+		return null;
+	}
+
+	/**
+	 * Compares an receiver to the argument Object.
+	 * 
+	 * @return int 0 - equal; 1 - this > val; -1 - this < val
+	 * @exception ClassCastException
+	 *                if the argument is not of type BigDecimal
+	 */
+	public int compareTo(Object o) {
+		return 0;
+	}
+
+	/**
+	 * Compares the receiver BigDecimal and argument BigDecimal e.x 1.00 & 1.0
+	 * will return 0 in compareTo.
+	 * 
+	 * @return int 0 - equal; 1 - this > val; -1 - this < val.
+	 */
+	public int compareTo(BigDecimal bval) {
+		return 0;
+	}
+
+	/**
+	 * Answers the result of (this / val).
+	 * 
+	 * @return BigDecimal result of this/val.
+	 */
+	public BigDecimal divide(BigDecimal bval, int roundingMode) {
+		return null;
+	}
+
+	/**
+	 * Answers the result of (this / val) and whose scale is specified.
+	 * 
+	 * @return BigDecimal result of this/val.
+	 * @exception ArithmeticException
+	 *                division by zero.
+	 * @exception IllegalArgumentException
+	 *                roundingMode is not valid.
+	 */
+	public BigDecimal divide(BigDecimal bval, int bscale, int roundingMode) {
+		return null;
+	}
+
+	/**
+	 * Converts this BigDecimal to a double. If magnitude of the BigDecimal
+	 * value is larger than what can be represented by a double, either Infinity
+	 * or -Infinity is returned.
+	 * 
+	 * @return double the value of the receiver.
+	 */
+	public double doubleValue() {
+		return 0;
+	}
+
+	/**
+	 * Compares the argument to the receiver, and answers true if they represent
+	 * the <em>same</em> object using a class specific comparison. The
+	 * implementation in Object answers true only if the argument is the exact
+	 * same object as the receiver (==).
+	 * 
+	 * @param o
+	 *            Object the object to compare with this object.
+	 * @return boolean <code>true</code> if the object is the same as this
+	 *         object <code>false</code> if it is different from this object.
+	 * @see hashCode
+	 */
+	public boolean equals(Object obj) {
+		return false;
+	}
+
+	/**
+	 * Converts this BigDecimal to a float.If magnitude of the BigDecimal value
+	 * is larger than what can be represented by a float, either Infinity or
+	 * -Infinity is returned.
+	 * 
+	 * @return float the value of the receiver.
+	 */
+	public float floatValue() {
+		return 0;
+	}
+
+	/**
+	 * Answers an integer hash code for the receiver. Any two objects which
+	 * answer <code>true</code> when passed to <code>.equals</code> must
+	 * answer the same value for this method.
+	 * 
+	 * @return int the receiver's hash.
+	 * 
+	 * @see #equals(Object)
+	 */
+	public int hashCode() {
+		return 0;
+	}
+
+	/**
+	 * Converts this BigDecimal to an int.
+	 * 
+	 * @return int the value of the receiver.
+	 */
+	public int intValue() {
+		return 0;
+	}
+
+	/**
+	 * Converts this BigDecimal to a long.
+	 * 
+	 * @return long long representation of the receiver.
+	 */
+	public long longValue() {
+		return 0;
+	}
+
+	/**
+	 * Answers the max value between the receiver and this BigDecimal.
+	 * 
+	 * @return BigDecimal max BigDecimal.
+	 */
+	public BigDecimal max(BigDecimal bval) {
+		return null;
+	}
+
+	/**
+	 * Answers the min value between the receiver and argument.
+	 * 
+	 * @return BigDecimal max BigDecimal.
+	 */
+	public BigDecimal min(BigDecimal bval) {
+		return null;
+	}
+
+	/**
+	 * Moves the decimal point of this BigDecimal n places to the left.
+	 * 
+	 * @return BigDecimal new BigDecimal with decimal moved n places to the
+	 *         left.
+	 */
+	public BigDecimal movePointLeft(int n) {
+		return null;
+	}
+
+	/**
+	 * Moves the decimal point of this BigDecimal n places to the right.
+	 * 
+	 * @return BigDecimal new BigDecimal with decimal moved n places to the
+	 *         right.
+	 */
+	public BigDecimal movePointRight(int n) {
+		return null;
+	}
+
+	/**
+	 * Answers the multiplication result of the receiver and argument.
+	 * 
+	 * @return BigDecimal result of multiplying two bigDecimals.
+	 */
+	public BigDecimal multiply(BigDecimal bval) {
+		return null;
+	}
+
+	/**
+	 * Negates this BigDecimal value.
+	 * 
+	 * @return BigDecimal new BigDecimal with value negated.
+	 */
+	public BigDecimal negate() {
+		return null;
+	}
+
+	/**
+	 * Returns the scale of this BigDecimal.
+	 * 
+	 * @return int scale value.
+	 */
+	public int scale() {
+		return 0;
+	}
+
+	/**
+	 * Sets the scale of this BigDecimal.
+	 * 
+	 * @return BigDecimal a BigDecimal with the same value, but specified scale.
+	 */
+	public BigDecimal setScale(int newScale) {
+		return null;
+	}
+
+	/**
+	 * Sets the scale of this BigDecimal. The unscaled value is determined by
+	 * the rounding Mode
+	 * 
+	 * @return BigDecimal a BigDecimal with the same value, but specified cale.
+	 * @exception ArithmeticException
+	 *                rounding mode must be specified if lose of precision due
+	 *                to setting scale.
+	 * @exception IllegalArgumentException
+	 *                invalid rounding mode
+	 */
+	public BigDecimal setScale(int newScale, int roundingMode) {
+		return null;
+	}
+
+	/**
+	 * Answers the signum function of this instance.
+	 * 
+	 * @return int -1, 0, or 1 if the receiver is negative, zero, or positive.
+	 */
+	public int signum() {
+		return 0;
+	}
+
+	/**
+	 * Answers the subtract result of the receiver and argument.
+	 * 
+	 * @return BigDecimal The result of adding two BigDecimal.
+	 */
+	public BigDecimal subtract(BigDecimal bval) {
+		return null;
+	}
+
+	/**
+	 * Converts this to a BigInteger.
+	 * 
+	 * @return BigInteger BigDecimal equivalent of bigInteger.
+	 */
+	public BigInteger toBigInteger() {
+		return null;
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver.
+	 * 
+	 * @return String a printable representation for the receiver.
+	 */
+	public String toString() {
+		return null;
+	}
+
+	/**
+	 * Returns an unscaled value of this BigDecimal.
+	 * 
+	 * @return BigInteger The unscaled value.
+	 */
+	public BigInteger unscaledValue() {
+		return null;
+	}
+
+	/**
+	 * Translate long value into a BigDecimal with scale of zero.
+	 * 
+	 * @return BigDecimal BigDecimal equivalence of a long value.
+	 */
+	public static BigDecimal valueOf(long bval) {
+		return null;
+	}
+
+	/**
+	 * Translate long unscaled value into a BigDecimal specified by the scale.
+	 * 
+	 * @return BigDecimal BigDecimal equalvalence of a long value.
+	 * @exception NumberFormatException
+	 *                the scale value is < 0;
+	 */
+	public static BigDecimal valueOf(long bval, int scale) {
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigInteger.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigInteger.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigInteger.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/math/src/java/math/BigInteger.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,617 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.math;
+
+import java.util.Random;
+
+
+/**
+ * BigInteger objects represent arbitrary precision decimal integers. They
+ * contain values that cannot be changed. Thus, most operations on the
+ * BigInteger objects yield new instances of BigInteger.
+ */
+public class BigInteger extends Number implements Comparable {
+	// Version ID indicating compatability with standard.
+	static final long serialVersionUID = -8287574255936472291L;
+
+	/**
+	 * Constant: 0 as represented by a BigInteger.
+	 */
+	public final static BigInteger ZERO = null;
+
+	/**
+	 * Constant: 1 as represented by a BigInteger.
+	 */
+	public final static BigInteger ONE = null;
+
+	/**
+	 * Answers a new instance of this class whose value is greater than zero,
+	 * length is the given number of bits, and whose likeyhood of being prime is
+	 * not less than 2 ^ -100.
+	 * 
+	 * @param bitLength
+	 *            the number of bits contained in the returned instance.
+	 * @param rnd
+	 *            a random source of bits for selection of the probable prime.
+	 * @return the probable prime number.
+	 */
+	public static BigInteger probablePrime(int bitLength, Random rnd) {
+		return null;
+	}
+
+	/**
+	 * Constructs a new instance of this class of the specified length, whose
+	 * content is produced by aquiring random bits from the specified random
+	 * number generator.
+	 * 
+	 * @param bitLength
+	 *            int the number of bits to have in the result.
+	 * @param rnd
+	 *            Random the generator to produce the bits.
+	 */
+	public BigInteger(int bitLength, Random rnd) {
+	}
+
+	/**
+	 * Constructs a new instance of this class of the specified length, whose
+	 * content is produced by aquiring random bits from the specified random
+	 * number generator. The result is guaranteed to be prime up to the given
+	 * degree of certainty.
+	 * 
+	 * @param bitLength
+	 *            int the number of bits to have in the result.
+	 * @param certainty
+	 *            int the degree of certainty required that the result is prime.
+	 * @param rnd
+	 *            Random the generator to produce the bits.
+	 */
+	public BigInteger(int bitLength, int certainty, Random rnd) {
+	}
+
+	/**
+	 * Constructs a new instance of this class given an array containing bytes
+	 * representing the bit pattern for the answer.
+	 * 
+	 * @param bytes
+	 *            byte[] the bits of the value of the new instance.
+	 */
+	public BigInteger(byte[] bytes) {
+	}
+
+	/**
+	 * Constructs a new instance of this class given an array containing bytes
+	 * representing the bit pattern for the answer, and a sign flag.
+	 * 
+	 * @param sign
+	 *            int the sign of the result.
+	 * @param bytes
+	 *            byte[] the bits of the value of the new instance.
+	 */
+	public BigInteger(int sign, byte[] bytes) {
+	}
+
+	/**
+	 * Answers an array of bytes containing the value of the receiver in the
+	 * same format used by the matching constructor.
+	 * 
+	 * @return byte[] the bits of the value of the receiver.
+	 */
+	public byte[] toByteArray() {
+		return null;
+	}
+
+	/**
+	 * Answers true if the receiver is probably prime to the given degree of
+	 * certainty.
+	 * 
+	 * @param certainty
+	 *            int the degree of certainty required.
+	 * @return boolean true if the receiver is prime and false otherwise.
+	 */
+	public boolean isProbablePrime(int certainty) {
+		return false;
+	}
+
+	/**
+	 * Compares the argument to the receiver, and answers true if they represent
+	 * the <em>same</em> object using a class specific comparison. In this
+	 * case the argument must also be a BigInteger which represents the same
+	 * number
+	 * 
+	 * @param o
+	 *            Object the object to compare with this object.
+	 * @return boolean <code>true</code> if the object is the same as this
+	 *         object <code>false</code> if it is different from this object.
+	 * @see #hashCode
+	 */
+	public boolean equals(Object o) {
+		return false;
+	}
+
+	/**
+	 * Answers an integer indicating the relative positions of the receiver and
+	 * the argument in the natural order of elements of the receiver's class.
+	 * 
+	 * @return int which should be <0 if the receiver should sort before the
+	 *         argument, 0 if the receiver should sort in the same position as
+	 *         the argument, and >0 if the receiver should sort after the
+	 *         argument.
+	 * @param val
+	 *            BigInteger an object to compare the receiver to
+	 * @exception ClassCastException
+	 *                if the argument can not be converted into something
+	 *                comparable with the receiver.
+	 */
+	public int compareTo(BigInteger val) {
+		return 0;
+	}
+
+	/**
+	 * Answers an integer indicating the relative positions of the receiver and
+	 * the argument in the natural order of elements of the receiver's class.
+	 * 
+	 * @return int which should be <0 if the receiver should sort before the
+	 *         argument, 0 if the receiver should sort in the same position as
+	 *         the argument, and >0 if the receiver should sort after the
+	 *         argument.
+	 * @param o
+	 *            Object an object to compare the receiver to
+	 * @exception ClassCastException
+	 *                if the argument can not be converted into something
+	 *                comparable with the receiver.
+	 */
+	public int compareTo(Object o) {
+		return 0;
+	}
+
+	/**
+	 * Answers the int value which the receiver represents
+	 * 
+	 * @return int the value of the receiver.
+	 */
+	public int intValue() {
+		return 0;
+	}
+
+	/**
+	 * Answers the long value which the receiver represents
+	 * 
+	 * @return long the value of the receiver.
+	 */
+	public long longValue() {
+		return 0;
+	}
+
+	/**
+	 * Answers a BigInteger with the same value as val
+	 * 
+	 * @return BigInteger (BigInteger) val
+	 */
+	public static BigInteger valueOf(long val) {
+		return null;
+	}
+
+	/**
+	 * Answers the sum of the receiver and a BigInteger
+	 * 
+	 * @param val
+	 *            a BigInteger to add
+	 * 
+	 * @return BigInteger this + val
+	 */
+	public BigInteger add(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the negative of the receiver
+	 * 
+	 * @return BigInteger (-1) * this
+	 */
+	public BigInteger negate() {
+		return null;
+	}
+
+	/**
+	 * Answers the sign of the receiver
+	 * 
+	 * @return BigInteger -1, 0, or 1 if the receiver is negative, zero, or
+	 *         positive
+	 */
+	public int signum() {
+		return 0;
+	}
+
+	/**
+	 * Answers the absolute value of the receiver
+	 * 
+	 * @return BigInteger absolute value of the receiver
+	 */
+	public BigInteger abs() {
+		return null;
+	}
+
+	/**
+	 * Answers the receiver to the power of exponent.
+	 * 
+	 * @exception ArithmeticException
+	 *                if the exponent is negative.
+	 * 
+	 * @return BigInteger this ^ exponent
+	 */
+	public BigInteger pow(int exponent) {
+		return null;
+	}
+
+	/**
+	 * Answers the receiver to the power of exponent modulo a BigInteger
+	 * 
+	 * @exception ArithmeticException
+	 *                modulo is <= 0
+	 * 
+	 * @return BigInteger this ^ exponent (mod modulo)
+	 */
+	public BigInteger modPow(BigInteger exponent, BigInteger modulo) {
+		return null;
+	}
+
+	/**
+	 * Answers the greatest common divisor of abs(this) and abs(val), zero if
+	 * this==val==0
+	 * 
+	 * @return BigInteger gcd(abs(this), abs(val))
+	 */
+	public BigInteger gcd(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the inverse of the receiver modulo a BigInteger, if it exists.
+	 * 
+	 * @param modulo
+	 *            BigInteger a BigInteger to divide
+	 * @return BigInteger this^(-1) (mod modulo)
+	 * 
+	 * @exception ArithmeticException
+	 *                if modulo is <= 0, or gcd(this,modulo) != 1
+	 */
+	public BigInteger modInverse(BigInteger modulo) {
+		return null;
+	}
+
+	/**
+	 * Answers the index of the lowest set bit in the receiver, or -1 if no bits
+	 * are set.
+	 * 
+	 * @return BigInteger the bit index of the least significant set bit in the
+	 *         receiver.
+	 */
+	public int getLowestSetBit() {
+		return 0;
+	}
+
+	/**
+	 * Answers a BigInteger with the value of the reciever divided by
+	 * 2^shiftval.
+	 * 
+	 * @param shiftval
+	 *            int the amount to shift the receiver.
+	 * @return BigInteger this >> val
+	 */
+	public BigInteger shiftRight(int shiftval) {
+		return null;
+	}
+
+	/**
+	 * Answers a BigInteger with the value of the reciever multiplied by
+	 * 2^shiftval.
+	 * 
+	 * @param shiftval
+	 *            int the amount to shift the receiver.
+	 * @return BigInteger this << val
+	 */
+	public BigInteger shiftLeft(int shiftval) {
+		return null;
+	}
+
+	/**
+	 * Answers the difference of the receiver and a BigInteger.
+	 * 
+	 * @param val
+	 *            BigInteger the value to subtract
+	 * @return BigInteger this - val
+	 */
+	public BigInteger subtract(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the product of the receiver and a BigInteger.
+	 * 
+	 * @param val
+	 *            BigInteger the value to multiply
+	 * @return BigInteger this * val
+	 */
+	public BigInteger multiply(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the quotient of the receiver and a BigInteger.
+	 * 
+	 * @param val
+	 *            BigInteger the value to divide
+	 * @return BigInteger this / val
+	 * 
+	 * @exception ArithmeticException
+	 *                if val is zero.
+	 */
+	public BigInteger divide(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the remainder of the receiver divided by a BigInteger
+	 * 
+	 * @param val
+	 *            a BigInteger to divide
+	 * 
+	 * @exception ArithmeticException
+	 *                if val is zero
+	 * 
+	 * @return BigInteger this % val
+	 */
+	public BigInteger remainder(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the remainder of the receiver modulo a BigInteger (a positive
+	 * value).
+	 * 
+	 * @param val
+	 *            the value to divide
+	 * @return BigInteger this (mod val)
+	 * 
+	 * @exception ArithmeticException
+	 *                if val is zero
+	 */
+	public BigInteger mod(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the quotient and remainder of the receiver divided by a
+	 * BigInteger.
+	 * 
+	 * @param val
+	 *            BigInteger the value to divide.
+	 * @return BigInteger[2] {this / val, this % val )}
+	 * 
+	 * @exception ArithmeticException
+	 *                if val is zero.
+	 */
+	public BigInteger[] divideAndRemainder(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Constructs a new instance of this class given a string containing a
+	 * representation of a decimal number.
+	 * 
+	 * @param val
+	 *            String the decimal digits of the answer.
+	 */
+	public BigInteger(String val) {
+	}
+
+	/**
+	 * Constructs a new instance of this class given a string containing digits
+	 * in the specified radix.
+	 * 
+	 * @param val
+	 *            String the digits of the answer.
+	 * @param radix
+	 *            int the radix to use for conversion.
+	 */
+	public BigInteger(String val, int radix) {
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver. In this case, a string of decimal digits.
+	 * 
+	 * @return String a printable representation for the receiver.
+	 */
+	public String toString() {
+		return this.toString(10);
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver as a sequence of digits in the specified radix.
+	 * 
+	 * @return String a printable representation for the receiver.
+	 */
+	public String toString(int radix) {
+		return null;
+	}
+
+	/**
+	 * Answers the most positive of either the receiver or the argument.
+	 * 
+	 * @param val
+	 *            BigInteger the value to compare.
+	 * @return BigInteger the larger value.
+	 */
+	public BigInteger max(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the most negative of either the receiver or the argument.
+	 * 
+	 * @param val
+	 *            BigInteger the value to compare.
+	 * @return BigInteger the smaller value.
+	 */
+	public BigInteger min(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers an integer hash code for the receiver. Any two objects which
+	 * answer <code>true</code> when passed to <code>.equals</code> must
+	 * answer the same value for this method.
+	 * 
+	 * @return int the receiver's hash.
+	 * 
+	 * @see #equals
+	 */
+	public int hashCode() {
+		return 0;
+	}
+
+	/**
+	 * Answers true if the specified bit is set in the receiver.
+	 * 
+	 * @param n
+	 *            int the bit to check.
+	 * @return boolean if the specified bit is set.
+	 */
+	public boolean testBit(int n) {
+		return false;
+	}
+
+	/**
+	 * Sets the specified bit in the receiver.
+	 * 
+	 * @param n
+	 *            int the bit to set.
+	 */
+	public BigInteger setBit(int n) {
+		return null;
+	}
+
+	/**
+	 * Unsets the specified bit in the receiver.
+	 * 
+	 * @param n
+	 *            int the bit to clear.
+	 */
+	public BigInteger clearBit(int n) {
+		return null;
+	}
+
+	/**
+	 * Toggles the specified bit in the receiver.
+	 * 
+	 * @param n
+	 *            int the bit to flip.
+	 */
+	public BigInteger flipBit(int n) {
+		return null;
+	}
+
+	/**
+	 * Answers the bitwise AND of the receiver and the argument.
+	 * 
+	 * @param val
+	 *            BigInteger the value to AND.
+	 * @return BigInteger this & val
+	 */
+	public BigInteger and(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the bitwise OR of the receiver and the argument.
+	 * 
+	 * @param val
+	 *            BigInteger the value to OR.
+	 * @return BigInteger this | val
+	 */
+	public BigInteger or(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the bitwise XOR of the receiver and the argument.
+	 * 
+	 * @param val
+	 *            BigInteger the value to XOR.
+	 * @return BigInteger this XOR val
+	 */
+	public BigInteger xor(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the bitwise negation of the receiver.
+	 * 
+	 * @return BigInteger NOT(this)
+	 */
+	public BigInteger not() {
+		return null;
+	}
+
+	/**
+	 * Answers the bitwise NAND of the receiver and the argument.
+	 * 
+	 * @param val
+	 *            BigInteger the value to NAND.
+	 * @return BigInteger this & NOT(val)
+	 */
+	public BigInteger andNot(BigInteger val) {
+		return null;
+	}
+
+	/**
+	 * Answers the length in bits of the receiver.
+	 * 
+	 * @return int the receiver's bit length.
+	 */
+	public int bitLength() {
+		return 0;
+	}
+
+	/**
+	 * Answers the number of set bits in the receiver.
+	 * 
+	 * @return int the receiver's bit count.
+	 */
+	public int bitCount() {
+		return 0;
+	}
+
+	/**
+	 * Answers the double value which the receiver represents
+	 * 
+	 * @return double the value of the receiver.
+	 */
+	public double doubleValue() {
+		return 0;
+	}
+
+	/**
+	 * Answers the float value which the receiver represents
+	 * 
+	 * @return float the value of the receiver.
+	 */
+	public float floatValue() {
+		return 0;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/META-INF/MANIFEST.MF?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/META-INF/MANIFEST.MF (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/META-INF/MANIFEST.MF Wed Nov 30 21:29:27 2005
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Harmony NIO
+Bundle-SymbolicName: org.apache.harmony.nio
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .
+Eclipse-JREBundle: true
+Export-Package: java.nio,
+ java.nio.channels,
+ java.nio.channels.spi,
+ com.ibm.io.nio.factory
+Import-Package: java.io,
+ java.lang,
+ java.lang.ref,
+ java.net,
+ java.nio.charset,
+ java.util
+Require-Bundle: org.apache.harmony.luni,
+ org.apache.harmony.nio_char
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BaseByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BaseByteBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BaseByteBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BaseByteBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,76 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+import java.nio.ShortBuffer;
+
+/**
+ * Serves as the root of other byte buffer impl classes, implements common
+ * methods that can be shared by child classes.
+ * 
+ */
+abstract class BaseByteBuffer extends ByteBuffer {
+
+	protected BaseByteBuffer(int capacity) {
+		super(capacity);
+	}
+
+	public final CharBuffer asCharBuffer() {
+		return CharToByteBufferAdapter.wrap(this);
+	}
+
+	public final DoubleBuffer asDoubleBuffer() {
+		return DoubleToByteBufferAdapter.wrap(this);
+	}
+
+	public final FloatBuffer asFloatBuffer() {
+		return FloatToByteBufferAdapter.wrap(this);
+	}
+
+	public final IntBuffer asIntBuffer() {
+		return IntToByteBufferAdapter.wrap(this);
+	}
+
+	public final LongBuffer asLongBuffer() {
+		return LongToByteBufferAdapter.wrap(this);
+	}
+
+	public final ShortBuffer asShortBuffer() {
+		return ShortToByteBufferAdapter.wrap(this);
+	}
+
+	public final char getChar() {
+		return (char) getShort();
+	}
+
+	public final char getChar(int index) {
+		return (char) getShort(index);
+	}
+
+	public final ByteBuffer putChar(char value) {
+		return putShort((short) value);
+	}
+
+	public final ByteBuffer putChar(int index, char value) {
+		return putShort(index, (short) value);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BufferFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BufferFactory.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BufferFactory.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/BufferFactory.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,235 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.ShortBuffer;
+import java.nio.channels.FileChannel.MapMode;
+
+/**
+ * Provide factory service of buffer classes.
+ * <p>
+ * Since all buffer impl classes are package private (except DirectByteBuffer),
+ * this factory is the only entrance to access buffer functions from outside of
+ * the impl package.
+ * </p>
+ * 
+ */
+public final class BufferFactory {
+
+	/**
+	 * Returns a new byte buffer based on the specified byte array.
+	 * 
+	 * @param array
+	 *            The byte array
+	 * @return A new byte buffer based on the specified byte array.
+	 */
+	public static ByteBuffer newByteBuffer(byte array[]) {
+		return new ReadWriteHeapByteBuffer(array);
+	}
+
+	/**
+	 * Returns a new array based byte buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new array based byte buffer with the specified capacity.
+	 */
+	public static ByteBuffer newByteBuffer(int capacity) {
+		return new ReadWriteHeapByteBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new char buffer based on the specified char array.
+	 * 
+	 * @param array
+	 *            The char array
+	 * @return A new char buffer based on the specified char array.
+	 */
+	public static CharBuffer newCharBuffer(char array[]) {
+		return new ReadWriteCharArrayBuffer(array);
+	}
+
+	/**
+	 * Returns a new readonly char buffer based on the specified char sequence.
+	 * 
+	 * @param chseq
+	 *            The char sequence
+	 * @return A new readonly char buffer based on the specified char sequence.
+	 */
+	public static CharBuffer newCharBuffer(CharSequence chseq) {
+		return new CharSequenceAdapter(chseq);
+	}
+
+	/**
+	 * Returns a new array based char buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new array based char buffer with the specified capacity.
+	 */
+	public static CharBuffer newCharBuffer(int capacity) {
+		return new ReadWriteCharArrayBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new direct byte buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new direct byte buffer with the specified capacity.
+	 */
+	public static ByteBuffer newDirectByteBuffer(int capacity) {
+		return new ReadWriteDirectByteBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new double buffer based on the specified double array.
+	 * 
+	 * @param array
+	 *            The double array
+	 * @return A new double buffer based on the specified double array.
+	 */
+	public static DoubleBuffer newDoubleBuffer(double array[]) {
+		return new ReadWriteDoubleArrayBuffer(array);
+	}
+
+	/**
+	 * Returns a new array based double buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new array based double buffer with the specified capacity.
+	 */
+	public static DoubleBuffer newDoubleBuffer(int capacity) {
+		return new ReadWriteDoubleArrayBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new float buffer based on the specified float array.
+	 * 
+	 * @param array
+	 *            The float array
+	 * @return A new float buffer based on the specified float array.
+	 */
+	public static FloatBuffer newFloatBuffer(float array[]) {
+		return new ReadWriteFloatArrayBuffer(array);
+	}
+
+	/**
+	 * Returns a new array based float buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new array based float buffer with the specified capacity.
+	 */
+	public static FloatBuffer newFloatBuffer(int capacity) {
+		return new ReadWriteFloatArrayBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new array based int buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new array based int buffer with the specified capacity.
+	 */
+	public static IntBuffer newIntBuffer(int capacity) {
+		return new ReadWriteIntArrayBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new int buffer based on the specified int array.
+	 * 
+	 * @param array
+	 *            The int array
+	 * @return A new int buffer based on the specified int array.
+	 */
+	public static IntBuffer newIntBuffer(int array[]) {
+		return new ReadWriteIntArrayBuffer(array);
+	}
+
+	/**
+	 * Returns a new array based long buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new array based long buffer with the specified capacity.
+	 */
+	public static LongBuffer newLongBuffer(int capacity) {
+		return new ReadWriteLongArrayBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new long buffer based on the specified long array.
+	 * 
+	 * @param array
+	 *            The long array
+	 * @return A new long buffer based on the specified long array.
+	 */
+	public static LongBuffer newLongBuffer(long array[]) {
+		return new ReadWriteLongArrayBuffer(array);
+	}
+
+	/**
+	 * Returns a new byte buffer mapped to the specified region of file.
+	 * 
+	 * @param mappedFile
+	 *            The file to be mapped
+	 * @param offset
+	 *            The offset of the region
+	 * @param size
+	 *            The size of the region
+	 * @param mapMode
+	 *            The map mode
+	 * @return A new byte buffer mapped to the specified region of file.
+	 */
+	public static MappedByteBuffer newMappedByteBuffer(File mappedFile,
+			long offset, int size, MapMode mapMode) {
+		return new MappedToByteBufferAdapter(mappedFile, offset, size, mapMode);
+	}
+
+	/**
+	 * Returns a new array based short buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of the new buffer
+	 * @return A new array based short buffer with the specified capacity.
+	 */
+	public static ShortBuffer newShortBuffer(int capacity) {
+		return new ReadWriteShortArrayBuffer(capacity);
+	}
+
+	/**
+	 * Returns a new short buffer based on the specified short array.
+	 * 
+	 * @param array
+	 *            The short array
+	 * @return A new short buffer based on the specified short array.
+	 */
+	public static ShortBuffer newShortBuffer(short array[]) {
+		return new ReadWriteShortArrayBuffer(array);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,93 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferUnderflowException;
+import java.nio.ByteOrder;
+import java.nio.CharBuffer;
+
+/**
+ * CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose
+ * the implementation of array based char buffers.
+ * <p>
+ * CharArrayBuffer implements all the shared readonly methods and is extended by
+ * the other two classes.
+ * </p>
+ * <p>
+ * All methods are marked final for runtime performance.
+ * </p>
+ * 
+ */
+abstract class CharArrayBuffer extends CharBuffer {
+
+	protected final char[] backingArray;
+
+	protected final int offset;
+
+	CharArrayBuffer(char[] array) {
+		this(array.length, array, 0);
+	}
+
+	CharArrayBuffer(int capacity) {
+		this(capacity, new char[capacity], 0);
+	}
+
+	CharArrayBuffer(int capacity, char[] backingArray, int offset) {
+		super(capacity);
+		this.backingArray = backingArray;
+		this.offset = offset;
+	}
+
+	public final char get() {
+		if (position == limit) {
+			throw new BufferUnderflowException();
+		}
+		return backingArray[offset + position++];
+	}
+
+	public final char get(int index) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return backingArray[offset + index];
+	}
+
+	public final boolean isDirect() {
+		return false;
+	}
+
+	public final ByteOrder order() {
+		return ByteOrder.nativeOrder();
+	}
+
+	public final CharSequence subSequence(int start, int end) {
+		if (start < 0 || start > remaining()) {
+			throw new IndexOutOfBoundsException();
+		}
+		if (end < start || end > remaining()) {
+			throw new IndexOutOfBoundsException();
+		}
+		CharBuffer result = duplicate();
+		result.limit(position + end);
+		result.position(position + start);
+		return result;
+	}
+
+	public final String toString() {
+		return String.copyValueOf(backingArray, offset + position, remaining());
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharSequenceAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharSequenceAdapter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharSequenceAdapter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharSequenceAdapter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,125 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferUnderflowException;
+import java.nio.ByteOrder;
+import java.nio.CharBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * This class wraps a char sequence to be a char buffer.
+ * <p>
+ * Implementation notice:
+ * <ul>
+ * <li>Char sequence based buffer is always readonly.</li>
+ * </ul>
+ * </p>
+ * 
+ */
+final class CharSequenceAdapter extends CharBuffer {
+
+	static CharSequenceAdapter copy(CharSequenceAdapter other) {
+		CharSequenceAdapter buf = new CharSequenceAdapter(other.sequence);
+		buf.limit = other.limit;
+		buf.position = other.position;
+		buf.mark = other.mark;
+		return buf;
+	}
+
+	final CharSequence sequence;
+
+	CharSequenceAdapter(CharSequence chseq) {
+		super(chseq.length());
+		sequence = chseq;
+	}
+
+	public CharBuffer asReadOnlyBuffer() {
+		return duplicate();
+	}
+
+	public CharBuffer compact() {
+		throw new ReadOnlyBufferException();
+	}
+
+	public CharBuffer duplicate() {
+		return copy(this);
+	}
+
+	public char get() {
+		if (position == limit) {
+			throw new BufferUnderflowException();
+		}
+		return sequence.charAt(position++);
+	}
+
+	public char get(int index) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return sequence.charAt(index);
+	}
+
+	public boolean isDirect() {
+		return false;
+	}
+
+	public boolean isReadOnly() {
+		return true;
+	}
+
+	public ByteOrder order() {
+		return ByteOrder.nativeOrder();
+	}
+
+	protected char[] protectedArray() {
+		throw new UnsupportedOperationException();
+	}
+
+	protected int protectedArrayOffset() {
+		throw new UnsupportedOperationException();
+	}
+
+	protected boolean protectedHasArray() {
+		return false;
+	}
+
+	public CharBuffer put(char c) {
+		throw new ReadOnlyBufferException();
+	}
+
+	public CharBuffer put(int index, char c) {
+		throw new ReadOnlyBufferException();
+	}
+
+	public CharBuffer slice() {
+		return new CharSequenceAdapter(sequence.subSequence(position, limit));
+	}
+
+	public CharSequence subSequence(int start, int end) {
+		if (start < 0 || start > remaining()) {
+			throw new IndexOutOfBoundsException();
+		}
+		if (end < start || end > remaining()) {
+			throw new IndexOutOfBoundsException();
+		}
+		CharSequenceAdapter result = copy(this);
+		result.position = position + start;
+		result.limit = position + end;
+		return result;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharToByteBufferAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharToByteBufferAdapter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharToByteBufferAdapter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/CharToByteBufferAdapter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,159 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.CharBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * This class wraps a byte buffer to be a char buffer.
+ * <p>
+ * Implementation notice:
+ * <ul>
+ * <li>After a byte buffer instance is wrapped, it becomes privately owned by
+ * the adapter. It must NOT be accessed outside the adapter any more.</li>
+ * <li>The byte buffer's position and limit are NOT linked with the adapter.
+ * The adapter extends Buffer, thus has its own position and limit.</li>
+ * </ul>
+ * </p>
+ * 
+ */
+final class CharToByteBufferAdapter extends CharBuffer {
+
+	static CharBuffer wrap(ByteBuffer byteBuffer) {
+		return new CharToByteBufferAdapter(byteBuffer.slice());
+	}
+
+	private final ByteBuffer byteBuffer;
+
+	CharToByteBufferAdapter(ByteBuffer byteBuffer) {
+		super((byteBuffer.capacity() >> 1));
+		this.byteBuffer = byteBuffer;
+		this.byteBuffer.clear();
+	}
+
+	public CharBuffer asReadOnlyBuffer() {
+		CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer
+				.asReadOnlyBuffer());
+		buf.limit = limit;
+		buf.position = position;
+		buf.mark = mark;
+		return buf;
+	}
+
+	public CharBuffer compact() {
+		if (byteBuffer.isReadOnly()) {
+			throw new ReadOnlyBufferException();
+		}
+		byteBuffer.limit(limit << 1);
+		byteBuffer.position(position << 1);
+		byteBuffer.compact();
+		byteBuffer.clear();
+		position = limit - position;
+		limit = capacity;
+		mark = UNSET_MARK;
+		return this;
+	}
+
+	public CharBuffer duplicate() {
+		CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer
+				.duplicate());
+		buf.limit = limit;
+		buf.position = position;
+		buf.mark = mark;
+		return buf;
+	}
+
+	public char get() {
+		if (position == limit) {
+			throw new BufferUnderflowException();
+		}
+		return byteBuffer.getChar(position++ << 1);
+	}
+
+	public char get(int index) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return byteBuffer.getChar(index << 1);
+	}
+
+	public boolean isDirect() {
+		return byteBuffer.isDirect();
+	}
+
+	public boolean isReadOnly() {
+		return byteBuffer.isReadOnly();
+	}
+
+	public ByteOrder order() {
+		return byteBuffer.order();
+	}
+
+	protected char[] protectedArray() {
+		throw new UnsupportedOperationException();
+	}
+
+	protected int protectedArrayOffset() {
+		throw new UnsupportedOperationException();
+	}
+
+	protected boolean protectedHasArray() {
+		return false;
+	}
+
+	public CharBuffer put(char c) {
+		if (position == limit) {
+			throw new BufferOverflowException();
+		}
+		byteBuffer.putChar(position++ << 1, c);
+		return this;
+	}
+
+	public CharBuffer put(int index, char c) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		byteBuffer.putChar(index << 1, c);
+		return this;
+	}
+
+	public CharBuffer slice() {
+		byteBuffer.limit(limit << 1);
+		byteBuffer.position(position << 1);
+		CharBuffer result = new CharToByteBufferAdapter(byteBuffer.slice());
+		byteBuffer.clear();
+		return result;
+	}
+
+	public CharSequence subSequence(int start, int end) {
+		if (start < 0 || start > remaining()) {
+			throw new IndexOutOfBoundsException();
+		}
+		if (end < start || end > remaining()) {
+			throw new IndexOutOfBoundsException();
+		}
+		CharBuffer result = duplicate();
+		result.limit(position + end);
+		result.position(position + start);
+		return result;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,231 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferUnderflowException;
+
+import com.ibm.platform.struct.PlatformAddress;
+
+/**
+ * DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer
+ * compose the implementation of platform memory based byte buffers.
+ * <p>
+ * DirectByteBuffer implements all the shared readonly methods and is extended
+ * by the other two classes.
+ * </p>
+ * <p>
+ * All methods are marked final for runtime performance.
+ * </p>
+ * 
+ */
+abstract class DirectByteBuffer extends BaseByteBuffer {
+
+	// This private class will help us track whether the address is valid or
+	// not.
+	protected static final class SafeAddress {
+		protected boolean isValid = true;
+
+		protected final PlatformAddress address;
+
+		protected SafeAddress(PlatformAddress address) {
+			super();
+			this.address = address;
+		}
+	}
+
+	// This is a wrapped reference to the base address of the buffer memory.
+	protected final SafeAddress safeAddress;
+
+	// This is the offset from the base address at which this buffer logically
+	// starts.
+	protected final int offset;
+
+	DirectByteBuffer(int capacity) {
+		this(new SafeAddress(PlatformAddress.alloc(capacity)), capacity, 0);
+		safeAddress.address.autoFree();
+	}
+
+	DirectByteBuffer(SafeAddress address, int capacity, int offset) {
+		super(capacity);
+		this.safeAddress = address;
+		this.offset = offset;
+	}
+
+	public final byte get() {
+		if (position == limit) {
+			throw new BufferUnderflowException();
+		}
+		return getBaseAddress().getByte(offset + position++);
+	}
+
+	public final byte get(int index) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return getBaseAddress().getByte(offset + index);
+	}
+
+	public final double getDouble() {
+		int newPosition = position + 8;
+		if (newPosition > limit) {
+			throw new BufferUnderflowException();
+		}
+		double result = getBaseAddress().getDouble(offset + position, order);
+		position = newPosition;
+		return result;
+	}
+
+	public final double getDouble(int index) {
+		if (index < 0 || index + 8 > limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return getBaseAddress().getDouble(offset + index, order);
+	}
+
+	public final float getFloat() {
+		int newPosition = position + 4;
+		if (newPosition > limit) {
+			throw new BufferUnderflowException();
+		}
+		float result = getBaseAddress().getFloat(offset + position, order);
+		position = newPosition;
+		return result;
+	}
+
+	public final float getFloat(int index) {
+		if (index < 0 || index + 4 > limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return getBaseAddress().getFloat(offset + index, order);
+	}
+
+	public final int getInt() {
+		int newPosition = position + 4;
+		if (newPosition > limit) {
+			throw new BufferUnderflowException();
+		}
+		int result = getBaseAddress().getInt(offset + position, order);
+		position = newPosition;
+		return result;
+	}
+
+	public final int getInt(int index) {
+		if (index < 0 || index + 4 > limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return getBaseAddress().getInt(offset + index, order);
+	}
+
+	public final long getLong() {
+		int newPosition = position + 8;
+		if (newPosition > limit) {
+			throw new BufferUnderflowException();
+		}
+		long result = getBaseAddress().getLong(offset + position, order);
+		position = newPosition;
+		return result;
+	}
+
+	public final long getLong(int index) {
+		if (index < 0 || index + 8 > limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return getBaseAddress().getLong(offset + index, order);
+	}
+
+	public final short getShort() {
+		int newPosition = position + 2;
+		if (newPosition > limit) {
+			throw new BufferUnderflowException();
+		}
+		short result = getBaseAddress().getShort(offset + position, order);
+		position = newPosition;
+		return result;
+	}
+
+	public final short getShort(int index) {
+		if (index < 0 || index + 2 > limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return getBaseAddress().getShort(offset + index, order);
+	}
+
+	public final boolean isDirect() {
+		return true;
+	}
+
+	protected final boolean isAddressValid() {
+		return safeAddress.isValid;
+	}
+
+	protected final void addressValidityCheck() {
+		if (!isAddressValid()) {
+			throw new IllegalStateException(
+					"Cannot use the direct byte buffer after it has been explicitly freed."); //$NON-NLS-1$
+		}
+	}
+
+	private void markAddressInvalid() {
+		safeAddress.isValid = false;
+	}
+
+	/*
+	 * Answers the base address of the buffer (i.e. before offset).
+	 */
+	protected final PlatformAddress getBaseAddress() {
+		addressValidityCheck();
+		return safeAddress.address;
+	}
+
+	/**
+	 * Answers the platform address of the start of this buffer instance.
+	 * <em>You must not attempt to free the returned address!!</em> It may not
+	 * be an address that was explicitly malloc'ed (i.e. if this buffer is the
+	 * result of a split); and it may be memory shared by multiple buffers.
+	 * <p>
+	 * If you can guarantee that you want to free the underlying memory call the
+	 * #free() method on this instance -- generally applications will rely on
+	 * the garbage collector to autofree this memory.
+	 * </p>
+	 * 
+	 * @return the effective address of the start of the buffer.
+	 * @throws IllegalStateException
+	 *             if this buffer address is known to have been freed
+	 *             previously.
+	 */
+	final PlatformAddress getEffectiveAddress() {
+		return getBaseAddress().offsetBytes(offset);
+	}
+
+	/**
+	 * Explicitly free the memory used by this direct byte buffer. If the memory
+	 * has already been freed then this is a no-op. Once the memory has been
+	 * freed then operations requiring access to the memory will throw an
+	 * <code>IllegalStateException</code>.
+	 * <p>
+	 * Note this is is possible that the memory is freed by code that reaches
+	 * into the address and explicitly frees it 'beneith' us -- this is bad
+	 * form.
+	 * </p>
+	 */
+	final void free() {
+		if (isAddressValid()) {
+			markAddressInvalid();
+			safeAddress.address.free();
+		}
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffers.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffers.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffers.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DirectByteBuffers.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,86 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio; 
+
+
+import java.nio.ByteBuffer;
+
+import com.ibm.platform.struct.PlatformAddress;
+
+/**
+ * Helper class for operations on direct ByteBuffer
+ * 
+ * @see java.nio.ByteBuffer
+ */
+public class DirectByteBuffers {
+
+	/**
+	 * Explicitly frees the memory used by the given direct byte buffer.
+	 * <p>
+	 * If the memory is known to already have been freed then this is a no-op.
+	 * Once the memory has been freed then operations requiring access to the
+	 * memory will throw an <code>IllegalStateException</code>.
+	 * </p>
+	 * <p>
+	 * Note this is is possible that the memory is freed by code that reaches
+	 * into the address and explicitly frees it 'beneith' us -- this is bad
+	 * form.
+	 * </p>
+	 * 
+	 * @param directBuffer
+	 *            the direct byte buffer memory to free
+	 * @throws IllegalArgumentException
+	 *             if the buffer is <code>null</code> or is not a
+	 *             <em>direct</em> byte buffer.
+	 */
+	public static void free(ByteBuffer directBuffer) {
+		if ((directBuffer == null) || (!directBuffer.isDirect())) {
+			throw new IllegalArgumentException();
+		}
+		DirectByteBuffer buf = (DirectByteBuffer) directBuffer;
+		buf.free();
+	}
+
+	/**
+	 * Answers the platform address of the start of this buffer instance.
+	 * <em>You must not attempt to free the returned address!!</em> It may not
+	 * be an address that was explicitly malloc'ed (i.e. if this buffer is the
+	 * result of a split); and it may be memory shared by multiple buffers.
+	 * <p>
+	 * If you can guarantee that you want to free the underlying memory call the
+	 * #free() method on this instance -- generally applications will rely on
+	 * the garbage collector to autofree this memory.
+	 * </p>
+	 * 
+	 * @param directBuffer
+	 *            the direct byte buffer
+	 * @return the effective address of the start of the buffer.
+	 * @throws IllegalStateException
+	 *             if this buffer address is known to have been freed
+	 *             previously.
+	 */
+	public static PlatformAddress getEffectiveAddress(ByteBuffer directBuffer) {
+		return toDirectBuffer(directBuffer).getEffectiveAddress();
+	}
+
+	private static DirectByteBuffer toDirectBuffer(ByteBuffer directBuffer) {
+		if ((directBuffer == null) || (!directBuffer.isDirect())) {
+			throw new IllegalArgumentException();
+		}
+		return (DirectByteBuffer) directBuffer;
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,77 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio; 
+
+
+import java.nio.BufferUnderflowException;
+import java.nio.ByteOrder;
+import java.nio.DoubleBuffer;
+
+/**
+ * DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer
+ * compose the implementation of array based double buffers.
+ * <p>
+ * DoubleArrayBuffer implements all the shared readonly methods and is extended
+ * by the other two classes.
+ * </p>
+ * <p>
+ * All methods are marked final for runtime performance.
+ * </p>
+ * 
+ */
+abstract class DoubleArrayBuffer extends DoubleBuffer {
+
+	protected final double[] backingArray;
+
+	protected final int offset;
+
+	DoubleArrayBuffer(double[] array) {
+		this(array.length, array, 0);
+	}
+
+	DoubleArrayBuffer(int capacity) {
+		this(capacity, new double[capacity], 0);
+	}
+
+	DoubleArrayBuffer(int capacity, double[] backingArray, int offset) {
+		super(capacity);
+		this.backingArray = backingArray;
+		this.offset = offset;
+	}
+
+	public final double get() {
+		if (position == limit) {
+			throw new BufferUnderflowException();
+		}
+		return backingArray[offset + position++];
+	}
+
+	public final double get(int index) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return backingArray[offset + index];
+	}
+
+	public final boolean isDirect() {
+		return false;
+	}
+
+	public final ByteOrder order() {
+		return ByteOrder.nativeOrder();
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleToByteBufferAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleToByteBufferAdapter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleToByteBufferAdapter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/DoubleToByteBufferAdapter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,147 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.DoubleBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * This class wraps a byte buffer to be a double buffer.
+ * <p>
+ * Implementation notice:
+ * <ul>
+ * <li>After a byte buffer instance is wrapped, it becomes privately owned by
+ * the adapter. It must NOT be accessed outside the adapter any more.</li>
+ * <li>The byte buffer's position and limit are NOT linked with the adapter.
+ * The adapter extends Buffer, thus has its own position and limit.</li>
+ * </ul>
+ * </p>
+ * 
+ */
+final class DoubleToByteBufferAdapter extends DoubleBuffer {
+
+	static DoubleBuffer wrap(ByteBuffer byteBuffer) {
+		return new DoubleToByteBufferAdapter(byteBuffer.slice());
+	}
+
+	private final ByteBuffer byteBuffer;
+
+	DoubleToByteBufferAdapter(ByteBuffer byteBuffer) {
+		super((byteBuffer.capacity() >> 3));
+		this.byteBuffer = byteBuffer;
+		this.byteBuffer.clear();
+	}
+
+	public DoubleBuffer asReadOnlyBuffer() {
+		DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(
+				byteBuffer.asReadOnlyBuffer());
+		buf.limit = limit;
+		buf.position = position;
+		buf.mark = mark;
+		return buf;
+	}
+
+	public DoubleBuffer compact() {
+		if (byteBuffer.isReadOnly()) {
+			throw new ReadOnlyBufferException();
+		}
+		byteBuffer.limit(limit << 3);
+		byteBuffer.position(position << 3);
+		byteBuffer.compact();
+		byteBuffer.clear();
+		position = limit - position;
+		limit = capacity;
+		mark = UNSET_MARK;
+		return this;
+	}
+
+	public DoubleBuffer duplicate() {
+		DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(
+				byteBuffer.duplicate());
+		buf.limit = limit;
+		buf.position = position;
+		buf.mark = mark;
+		return buf;
+	}
+
+	public double get() {
+		if (position == limit) {
+			throw new BufferUnderflowException();
+		}
+		return byteBuffer.getDouble(position++ << 3);
+	}
+
+	public double get(int index) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		return byteBuffer.getDouble(index << 3);
+	}
+
+	public boolean isDirect() {
+		return byteBuffer.isDirect();
+	}
+
+	public boolean isReadOnly() {
+		return byteBuffer.isReadOnly();
+	}
+
+	public ByteOrder order() {
+		return byteBuffer.order();
+	}
+
+	protected double[] protectedArray() {
+		throw new UnsupportedOperationException();
+	}
+
+	protected int protectedArrayOffset() {
+		throw new UnsupportedOperationException();
+	}
+
+	protected boolean protectedHasArray() {
+		return false;
+	}
+
+	public DoubleBuffer put(double c) {
+		if (position == limit) {
+			throw new BufferOverflowException();
+		}
+		byteBuffer.putDouble(position++ << 3, c);
+		return this;
+	}
+
+	public DoubleBuffer put(int index, double c) {
+		if (index < 0 || index >= limit) {
+			throw new IndexOutOfBoundsException();
+		}
+		byteBuffer.putDouble(index << 3, c);
+		return this;
+	}
+
+	public DoubleBuffer slice() {
+		byteBuffer.limit(limit << 3);
+		byteBuffer.position(position << 3);
+		DoubleBuffer result = new DoubleToByteBufferAdapter(byteBuffer.slice());
+		byteBuffer.clear();
+		return result;
+	}
+
+}



Mime
View raw message