You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ar...@apache.org on 2006/05/02 01:11:49 UTC

svn commit: r398726 [5/6] - in /incubator/harmony/enhanced/classlibadapter: ./ trunk/ trunk/bin/ trunk/modules/ trunk/modules/kernel/ trunk/modules/kernel/src/ trunk/modules/kernel/src/main/ trunk/modules/kernel/src/main/java/ trunk/modules/kernel/src/...

Added: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessControlContext.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessControlContext.java?rev=398726&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessControlContext.java (added)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessControlContext.java Mon May  1 16:11:39 2006
@@ -0,0 +1,164 @@
+/* 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.security;
+
+/**
+ * The vm vendor may choose to implement this class. The reference
+ * implementation must be used if the reference implementation of
+ * AccessController is used.
+ * 
+ * An AccessControlContext encapsulates the information which is needed by class
+ * AccessController to detect if a Permission would be granted at a particular
+ * point in a programs execution.
+ * 
+ */
+
+public final class AccessControlContext {
+	DomainCombiner domainCombiner;
+
+	ProtectionDomain[] domainsArray;
+
+	private static final SecurityPermission createAccessControlContext = new SecurityPermission(
+			"createAccessControlContext");
+
+	private static final SecurityPermission getDomainCombiner = new SecurityPermission(
+			"getDomainCombiner");
+
+	/**
+	 * Constructs a new instance of this class given an array of protection
+	 * domains.
+	 * 
+	 */
+	public AccessControlContext(ProtectionDomain[] context) {
+		int length = context.length;
+		int domainIndex = 0;
+		this.domainsArray = new ProtectionDomain[length];
+		next: for (int i = 0; i < length; i++) {
+			ProtectionDomain current = context[i];
+			for (int j = 0; j < i; j++)
+				if (current == this.domainsArray[j])
+					continue next;
+			this.domainsArray[domainIndex++] = current;
+		}
+		if (domainIndex != length) {
+			ProtectionDomain[] copy = new ProtectionDomain[domainIndex];
+			System.arraycopy(this.domainsArray, 0, copy, 0, domainIndex);
+			this.domainsArray = copy;
+		}
+	}
+
+	AccessControlContext(ProtectionDomain[] context, boolean ignored) {
+		domainsArray = context;
+	}
+
+	/**
+	 * Constructs a new instance of this class given a context and a
+	 * DomainCombiner
+	 */
+	public AccessControlContext(AccessControlContext acc,
+			DomainCombiner combiner) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkPermission(createAccessControlContext);
+		this.domainsArray = acc.domainsArray;
+		this.domainCombiner = combiner;
+	}
+
+	/**
+	 * Checks if the permission <code>perm</code> is allowed in this context.
+	 * All ProtectionDomains must grant the permission for it to be granted.
+	 * 
+	 * @param perm
+	 *            java.security.Permission the permission to check
+	 * @exception java.security.AccessControlException
+	 *                thrown when perm is not granted.
+	 */
+	public void checkPermission(Permission perm) throws AccessControlException {
+		if (perm == null)
+			throw new NullPointerException();
+		int i = domainsArray.length;
+		while (--i >= 0 && domainsArray[i].implies(perm))
+			;
+		if (i >= 0) {
+			throw new AccessControlException("Access Denied", perm);
+		}
+	}
+
+	/**
+	 * 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, they must both be AccessControlContexts and contain the same
+	 * protection domains.
+	 * 
+	 * 
+	 * @param o
+	 *            the object to compare with this object
+	 * @return <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) {
+		if (this == o)
+			return true;
+		if (o == null || this.getClass() != o.getClass())
+			return false;
+		AccessControlContext otherContext = (AccessControlContext) o;
+		ProtectionDomain[] otherDomains = otherContext.domainsArray;
+		int length = domainsArray.length;
+		if (length != otherDomains.length)
+			return false;
+
+		next: for (int i = 0; i < length; i++) {
+			ProtectionDomain current = domainsArray[i];
+			for (int j = 0; j < length; j++)
+				if (current == otherDomains[j])
+					continue next;
+			return false;
+		}
+		return true;
+	}
+
+	/**
+	 * 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 the receiver's hash
+	 * 
+	 * @see #equals
+	 */
+	public int hashCode() {
+		int result = 0;
+		int i = domainsArray.length;
+		while (--i >= 0)
+			result ^= domainsArray[i].hashCode();
+		return result;
+	}
+
+	/**
+	 * Answers the DomainCombiner for the receiver.
+	 * 
+	 */
+	public DomainCombiner getDomainCombiner() {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkPermission(getDomainCombiner);
+		return domainCombiner;
+	}
+
+}
+

Propchange: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessControlContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessController.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessController.java?rev=398726&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessController.java (added)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessController.java Mon May  1 16:11:39 2006
@@ -0,0 +1,278 @@
+/* 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.security;
+
+/**
+ * This class must be implemented by the vm vendor, or the reference
+ * implementation can be used if the documented native is implemented.
+ * 
+ * Checks access to system resources. Supports marking of code as priveleged.
+ * Makes context snapshots to allow checking from other contexts.
+ * 
+ */
+
+public final class AccessController {
+	static {
+		// Initialize vm-internal caches
+		initializeInternal();
+	}
+
+    private static void initializeInternal() 
+    {
+        //fixit -- apparently this is not needed for simple "hello world" app.
+    }
+
+	/**
+	 * Prevents this class from being instantiated.
+	 */
+	private AccessController() {
+	}
+
+	/**
+	 * This native must be implemented to use the reference implementation of
+	 * this class. It is used by checkPermission() and getContext(), which call
+	 * this native with depth = 1.
+	 * 
+	 * Returns an array of ProtectionDomain from the classes on the stack, from
+	 * the specified depth up to the first privileged frame, or the end of the
+	 * stack if there is not a privileged frame. The array may be larger than
+	 * required, but must be null terminated. As bootstrap classes have all
+	 * permissions, bootstrap class frames SHOULD be skipped. Bootstrap class
+	 * frames MUST be skipped if the ProtectionDomain of bootstrap classes is
+	 * null. Duplicate ProtectionDomains SHOULD be removed.
+	 * 
+	 * The first element of the result is the AccessControlContext, which may be
+	 * null, either from the privileged frame, or from the current Thread if
+	 * there is not a privileged frame.
+	 * 
+	 * A privileged frame is any frame running one of the following methods:
+	 * 
+	 * <code><ul>
+	 * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;)Ljava/lang/Object;</li>
+	 * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;)Ljava/lang/Object;</li>
+	 * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;</li>
+	 * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;</li>
+	 * </ul></code>
+	 * 
+	 * @param depth
+	 *            The stack depth at which to start. Depth 0 is the current
+	 *            frame (the caller of this native).
+	 * 
+	 * @return an Object[] where the first element is AccessControlContext, and
+	 *         the other elements are ProtectionsDomain.
+	 */
+
+    private static Object[] getProtectionDomains(int depth) 
+    {
+        return null;  //this incorrect code is good enough for simple "hello world" demo
+    }
+
+	/**
+	 * Checks whether the running program is allowed to access the resource
+	 * being guarded by the given Permission argument.
+	 * 
+	 * 
+	 * @param perm
+	 *            the permission to check
+	 * @exception AccessControlException
+	 *                if access is not allowed.
+	 */
+	public static void checkPermission(Permission perm)
+			throws AccessControlException {
+		if (perm == null)
+			throw new NullPointerException();
+		Object[] domains = getProtectionDomains(1);
+		AccessControlContext acc = (AccessControlContext) domains[0];
+		ProtectionDomain[] pDomains = null;
+		if (acc != null && acc.domainCombiner != null) {
+			pDomains = acc.domainCombiner.combine(toArrayOfProtectionDomains(
+					domains, null), acc.domainsArray);
+		} else {
+			pDomains = toArrayOfProtectionDomains(domains, acc);
+		}
+		for (int i = 0, length = pDomains.length; i < length; i++) {
+			if (!pDomains[i].implies(perm)) {
+				throw new AccessControlException("Access Denied " + perm, perm);
+			}
+		}
+	}
+
+	/**
+	 * Used to keep the context live during doPrivileged().
+	 * 
+	 * 
+	 * @see #doPrivileged(PrivilegedAction, AccessControlContext)
+	 */
+	private static void keepalive(AccessControlContext context) {
+	}
+
+	/**
+	 * Answers the access controller context of the current thread, including
+	 * the inherited ones. It basically retrieves all the protection domains
+	 * from the calling stack and creates an <code>AccessControlContext</code>
+	 * with them.
+	 * 
+	 * 
+	 * @see AccessControlContext
+	 */
+	public static AccessControlContext getContext() {
+		Object[] domains = getProtectionDomains(1);
+		AccessControlContext acc = (AccessControlContext) domains[0];
+		ProtectionDomain[] pDomains = null;
+		if (acc != null && acc.domainCombiner != null) {
+			pDomains = acc.domainCombiner.combine(toArrayOfProtectionDomains(
+					domains, null), acc.domainsArray);
+			AccessControlContext result = new AccessControlContext(pDomains,
+					false);
+			result.domainCombiner = acc.domainCombiner;
+			return result;
+		}
+		return new AccessControlContext(
+				toArrayOfProtectionDomains(domains, acc), false);
+	}
+
+	private static ProtectionDomain[] toArrayOfProtectionDomains(
+			Object[] domains, AccessControlContext acc) {
+		int len = 0, size = domains.length - 1;
+		int extra = acc == null ? 0 : acc.domainsArray.length;
+		ProtectionDomain[] answer = new ProtectionDomain[size + extra];
+		for (int i = 1; i <= size; i++) {
+			boolean found = false;
+			if ((answer[len] = (ProtectionDomain) domains[i]) == null)
+				break;
+			if (acc != null) {
+				for (int j = 0; j < acc.domainsArray.length; j++) {
+					if (answer[len] == acc.domainsArray[j]) {
+						found = true;
+						break;
+					}
+				}
+			}
+			if (!found)
+				len++;
+		}
+		if (len == 0 && acc != null)
+			return acc.domainsArray;
+		else if (len < size) {
+			ProtectionDomain[] copy = new ProtectionDomain[len + extra];
+			System.arraycopy(answer, 0, copy, 0, len);
+			answer = copy;
+		}
+		if (acc != null)
+			System.arraycopy(acc.domainsArray, 0, answer, len,
+					acc.domainsArray.length);
+		return answer;
+	}
+
+	/**
+	 * Performs the privileged action specified by <code>action</code>.
+	 * <p>
+	 * When permission checks are made, if the permission has been granted by
+	 * all frames below and including the one representing the call to this
+	 * method, then the permission is granted. In otherwords, the check stops
+	 * here.
+	 * 
+	 * Any unchecked exception generated by this method will propagate up the
+	 * chain.
+	 * 
+	 * 
+	 * @see #doPrivileged(PrivilegedAction)
+	 */
+	public static Object doPrivileged(PrivilegedAction action) {
+		return action.run();
+	}
+
+	/**
+	 * Performs the privileged action specified by <code>action</code>.
+	 * <p>
+	 * When permission checks are made, if the permission has been granted by
+	 * all frames below and including the one representing the call to this
+	 * method, then the permission is granted iff it is granted by the
+	 * AccessControlContext <code>context</code>. In otherwords, no more
+	 * checking of the current stack is performed. Instead, the passed in
+	 * context is checked.
+	 * 
+	 * Any unchecked exception generated by this method will propagate up the
+	 * chain.
+	 * 
+	 * 
+	 * @see #doPrivileged(PrivilegedAction)
+	 */
+	public static Object doPrivileged(PrivilegedAction action,
+			AccessControlContext context) {
+		Object result = action.run();
+		keepalive(context);
+		return result;
+	}
+
+	/**
+	 * Performs the privileged action specified by <code>action</code>.
+	 * <p>
+	 * When permission checks are made, if the permission has been granted by
+	 * all frames below and including the one representing the call to this
+	 * method, then the permission is granted. In otherwords, the check stops
+	 * here.
+	 * 
+	 * Any unchecked exception generated by this method will propagate up the
+	 * chain. However, checked exceptions will be caught an re-thrown as
+	 * PrivilegedActionExceptions
+	 * 
+	 * 
+	 * @see #doPrivileged(PrivilegedAction)
+	 */
+	public static Object doPrivileged(PrivilegedExceptionAction action)
+			throws PrivilegedActionException {
+		try {
+			return action.run();
+		} catch (RuntimeException ex) {
+			throw ex;
+		} catch (Exception ex) {
+			throw new PrivilegedActionException(ex);
+		}
+	}
+
+	/**
+	 * Performs the privileged action specified by <code>action</code>.
+	 * <p>
+	 * When permission checks are made, if the permission has been granted by
+	 * all frames below and including the one representing the call to this
+	 * method, then the permission is granted iff it is granted by the
+	 * AccessControlContext <code>context</code>. In otherwords, no more
+	 * checking of the current stack is performed. Instead, the passed in
+	 * context is checked.
+	 * 
+	 * Any unchecked exception generated by this method will propagate up the
+	 * chain. However, checked exceptions will be caught an re-thrown as
+	 * PrivilegedActionExceptions
+	 * 
+	 * 
+	 * @see #doPrivileged(PrivilegedAction)
+	 */
+	public static Object doPrivileged(PrivilegedExceptionAction action,
+			AccessControlContext context) throws PrivilegedActionException {
+		try {
+			Object result = action.run();
+			keepalive(context);
+			return result;
+		} catch (RuntimeException ex) {
+			throw ex;
+		} catch (Exception ex) {
+			throw new PrivilegedActionException(ex);
+		}
+	}
+
+}
+

Propchange: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/security/AccessController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlibadapter/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlibadapter/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java?rev=398726&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java (added)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java Mon May  1 16:11:39 2006
@@ -0,0 +1,94 @@
+/* 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.io; 
+
+
+/**
+ * FileDescriptor is the lowest level representation of a File, Device, or
+ * Socket. You can create any of the IO classes which take a FileDescriptor as
+ * an argument by querying an open Socket or File for the FileDescriptor.
+ * <p>
+ * The FileDescriptor class also contains static fields representing Standard
+ * Input, Output and Error. You can use these directly if desired but it is
+ * recommended you go through System.in, System.out, and System.err streams
+ * respectively.
+ * <p>
+ * Applications should not create new FileDescriptors.
+ * 
+ * @see FileInputStream#getFD()
+ * @see FileOutputStream#getFD()
+ * @see RandomAccessFile#getFD()
+ */
+public final class FileDescriptor {
+	/** FileDescriptor representing Standard In */
+	public static final FileDescriptor in = new FileDescriptor();
+
+	/** FileDescriptor representing Standard Out */
+	public static final FileDescriptor out = new FileDescriptor();
+
+	/** FileDescriptor representing Standard Error */
+	public static final FileDescriptor err = new FileDescriptor();
+
+	/**
+	 * Represents a link to any underlying OS resources for this FileDescriptor.
+	 * A value of -1 indicates that this FileDescriptor is invalid.
+	 */
+	long descriptor = -1;
+
+	//private static native void oneTimeInitialization();  //fixit --- this line was replaced with the non-native code below
+    static int initCount;
+    private static void oneTimeInitialization()             //fixit ---- this code is sufficient to allow simple "hello world" demo to run
+    {
+        initCount++;
+    }
+
+	static {
+		in.descriptor = 0;
+		out.descriptor = 1;
+		err.descriptor = 2;
+
+		oneTimeInitialization();
+	}
+
+	/**
+	 * Constructs a new FileDescriptor containing an invalid handle. This
+	 * constructor does nothing interesting. Provided for signature
+	 * compatibility.
+	 * 
+	 */
+	public FileDescriptor() {
+		super();
+	}
+
+	/**
+	 * Ensures that data which is buffered within the underlying implementation
+	 * is written out to the appropriate device before returning.
+	 * 
+	 * @throws SyncFailedException
+	 *             when the operation fails
+	 */
+	public native void sync() throws SyncFailedException;
+
+	/**
+	 * Answers a boolean indicating whether or not this FileDescriptor is valid.
+	 * 
+	 * @return <code>true</code> if this FileDescriptor is valid,
+	 *         <code>false</code> otherwise
+	 */
+	public native boolean valid();
+
+}
+

Propchange: incubator/harmony/enhanced/classlibadapter/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSFileSystem.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSFileSystem.java?rev=398726&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSFileSystem.java (added)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSFileSystem.java Mon May  1 16:11:39 2006
@@ -0,0 +1,277 @@
+/* Copyright 2004, 2006 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.platform;
+
+import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * This is the portable implementation of the file system interface.
+ * 
+ */
+public class OSFileSystem extends OSComponent implements IFileSystem {
+
+	/**
+	 * 
+	 */
+	public OSFileSystem() {
+		super();
+	}
+
+	private final void validateLockArgs(int type, long start, long length) {
+		if ((type != IFileSystem.SHARED_LOCK_TYPE)
+				&& (type != IFileSystem.EXCLUSIVE_LOCK_TYPE)) {
+			throw new IllegalArgumentException("Illegal lock type requested."); //$NON-NLS-1$
+		}
+
+		// Start position
+		if (start < 0) {
+			throw new IllegalArgumentException(
+					"Lock start position must be non-negative"); //$NON-NLS-1$
+		}
+
+		// Length of lock stretch
+		if (length < 0) {
+			throw new IllegalArgumentException(
+					"Lock length must be non-negative"); //$NON-NLS-1$
+		}
+	}
+
+    private int lockImpl(long fileDescriptor, long start, long length,
+        int type, boolean wait) 
+    {
+        System.out.println("OSFileSystem.lockImpl() is not implemented yet");
+        return 0; //fixit -- returning a null is incorrect but it allows simple "hello world" to run
+    }
+
+    public int getPageSize() 
+    {
+        return 1024*4; //fixit -- just a wild guess. Need to find out what this value is supposed to be
+    }   
+
+	public boolean lock(long fileDescriptor, long start, long length, int type,
+			boolean waitFlag) throws IOException {
+		// Validate arguments
+		validateLockArgs(type, start, length);
+		int result = lockImpl(fileDescriptor, start, length, type, waitFlag);
+		return result != -1;
+	}
+
+    private int unlockImpl(long fileDescriptor, long start, long length) 
+    {
+        System.out.println("OSFileSystem.unlockImpl() is not implemented yet");
+        return 0; //fixit -- not yet implemented
+    }
+
+	public void unlock(long fileDescriptor, long start, long length)
+			throws IOException {
+		// Validate arguments
+		validateLockArgs(IFileSystem.SHARED_LOCK_TYPE, start, length);
+		int result = unlockImpl(fileDescriptor, start, length);
+		if (result == -1) {
+			throw new IOException();
+		}
+	}
+
+    private native int fflushImpl(long fd, boolean metadata);
+
+	public void fflush(long fileDescriptor, boolean metadata)
+			throws IOException {
+		int result = fflushImpl(fileDescriptor, metadata);
+		if (result == -1) {
+			throw new IOException();
+		}
+	}
+
+	/*
+	 * File position seeking.
+	 */
+
+    private native long seekImpl(long fd, long offset, int whence);
+
+	public long seek(long fileDescriptor, long offset, int whence)
+			throws IOException {
+		long pos = seekImpl(fileDescriptor, offset, whence);
+		if (pos == -1) {
+			throw new IOException();
+		}
+		return pos;
+	}
+
+	/*
+	 * Direct read/write APIs work on addresses.
+	 */
+    private long readDirectImpl(long fileDescriptor, long address,
+        int offset, int length) 
+    {
+        System.out.println("OSFileSystem.readDirectImpl() is not yet implemented");
+        return 0L;
+    }
+
+	public long readDirect(long fileDescriptor, long address, int offset,
+			int length) throws IOException {
+		long bytesRead = readDirectImpl(fileDescriptor, address, offset, length);
+		if (bytesRead < -1) {
+			throw new IOException();
+		}
+		return bytesRead;
+	}
+
+    private long writeDirectImpl(long fileDescriptor, long address,
+        int offset, int length) 
+    {
+        System.out.println("OSFileSystem.writeDirectImpl() is not yet implemented");
+        return 0;
+    }
+
+	public long writeDirect(long fileDescriptor, long address, int offset,
+			int length) throws IOException {
+		long bytesWritten = writeDirectImpl(fileDescriptor, address, offset,
+				length);
+		if (bytesWritten < 0) {
+			throw new IOException();
+		}
+		return bytesWritten;
+	}
+
+	/*
+	 * Indirect read/writes work on byte[]'s
+	 */
+    private native long readImpl(long fileDescriptor, byte[] oneByteArray);
+
+	public long read(long fileDescriptor, byte[] bytes, int offset, int length)
+			throws IOException {
+        byte [] oneByteArray = new byte[1];
+        for (int xx = offset; xx < offset + length; xx++) 
+        {
+            long stat = readImpl(fileDescriptor, oneByteArray);
+            if (stat == -1) 
+            {
+                System.out.println("OSFileSystem.read() -- error");
+                throw new IOException();
+            }
+            bytes[xx] = oneByteArray[0];
+        }
+		return length;
+	}
+
+    private native void writeImpl(long fileDescriptor, int theCharacterToBeWritten) ; //fixit -- need to allow for different fileDescriptor's
+
+	public long write(long fileDescriptor, byte[] bytes, int offset, int length)
+			throws IOException {
+        for (int xx = offset; xx < offset + length; xx++) 
+        {
+            int target = (int)bytes[xx];
+            writeImpl(fileDescriptor, target);
+        }
+		//if (bytesWritten < 0) {
+		//	throw new IOException();
+		//}
+        long bytesWritten = length;
+		return bytesWritten;
+        
+	}
+
+	/*
+	 * Scatter/gather calls.
+	 */
+	public long readv(long fileDescriptor, long[] addresses, int[] offsets,
+			int[] lengths, int size) throws IOException {
+		long bytesRead = readvImpl(fileDescriptor, addresses, offsets, lengths,
+				size);
+		if (bytesRead < -1) {
+			throw new IOException();
+		}
+		return bytesRead;
+	}
+
+    private long readvImpl(long fileDescriptor, long[] addresses,
+        int[] offsets, int[] lengths, int size) 
+    {
+        System.out.println("OSFileSystem.readvImpl() is not yet implemented");
+        return 0L;
+    }
+
+	public long writev(long fileDescriptor, long[] addresses, int[] offsets,
+			int[] lengths, int size) throws IOException {
+		long bytesWritten = writevImpl(fileDescriptor, addresses, offsets,
+				lengths, size);
+		if (bytesWritten < 0) {
+			throw new IOException();
+		}
+		return bytesWritten;
+	}
+
+    private long writevImpl(long fileDescriptor, long[] addresses,
+        int[] offsets, int[] lengths, int size) 
+    {
+        System.out.println("OSFileSystem.writevImpl() is not yet implemented");
+        return 0L;
+    }
+
+    private native int closeImpl(long fileDescriptor);
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see com.ibm.platform.IFileSystem#close(long)
+	 */
+	public void close(long fileDescriptor) throws IOException {
+		int rc = closeImpl(fileDescriptor);
+		if (rc == -1) {
+			throw new IOException();
+		}
+	}
+
+	public void truncate(long fileDescriptor, long size) throws IOException {
+		int rc = truncateImpl(fileDescriptor, size);
+		if (rc < 0) {
+			throw new IOException();
+		}
+	}
+
+    private native int truncateImpl(long fileDescriptor, long size);
+
+	public long open(byte[] fileName, int mode) throws FileNotFoundException {
+		if (fileName == null) {
+			throw new NullPointerException();
+		}
+		long handler = openImpl(fileName, mode);
+		if (handler < 0) {
+			throw new FileNotFoundException();
+		}
+		return handler;
+	}
+
+    private native long openImpl(byte[] fileName, int mode);
+
+	public long transfer(long fileHandler, FileDescriptor socketDescriptor,
+			long offset, long count) throws IOException {
+		long result = transferImpl(fileHandler, socketDescriptor, offset, count);
+		if (result < 0)
+			throw new IOException();
+		return result;
+	}
+
+    private long transferImpl(long fileHandler,
+        FileDescriptor socketDescriptor, long offset, long count) 
+    {
+        System.out.println("OSFileSystem.transferImpl() is not yet implemented");
+        return 0L;
+    }
+}
+

Propchange: incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSFileSystem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSMemory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSMemory.java?rev=398726&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSMemory.java (added)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSMemory.java Mon May  1 16:11:39 2006
@@ -0,0 +1,698 @@
+/* Copyright 2004, 2006 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.platform;
+
+import java.io.IOException;
+
+import org.apache.harmony.luni.util.NotYetImplementedException;
+
+import com.ibm.platform.struct.PlatformAddress;
+
+// import com.ibm.oti.vm.VM;
+
+/**
+ * This class enables direct access to OS memory.
+ * <p>
+ * Methods that take OS addresses define such parameters as a Java
+ * <code>long</code>. The <code>long</code> value is interpreted based on
+ * the underlying platform pointer size, such that only the lowest significant
+ * <code>POINTER_SIZE</code> bytes of the <code>long</code> value are used.
+ * In practice this means that methods on 64-bit platforms use the full eight
+ * bytes of the address parameter, and on 32-bit platforms the same methods are
+ * truncated to use only the low four bytes.
+ * </p>
+ * <p>
+ * Methods that return OS addresses define the return type to be a Java
+ * <code>long</code>. If the platform pointer size is less than eight bytes
+ * the OS address value is zero-extended to an eight-byte int to correspond to
+ * the subsequent interpretation of that jlong as an OS address as defined
+ * above.
+ * </p>
+ */
+final class OSMemory extends OSComponent implements IMemorySystem 
+{
+
+    /**
+     * Defines the size, in bytes, of a native pointer type for the underlying
+     * platform. This will be 4 (for 32-bit machines) or 8 (for 64-bit
+     * machines).
+     */
+    public static final int POINTER_SIZE;
+
+    /**
+     * Defines the natural byte order for this machine.
+     */
+    public static final Endianness NATIVE_ORDER;
+
+    private static final OSMemory singleton = new OSMemory();
+
+    static 
+    {
+        // FIXME: OSMemory, OSFileSystem, OSNetwork, should be moved to luni
+        System.loadLibrary("hynio");
+        POINTER_SIZE = getPointerSizeImpl();
+
+        if (isLittleEndianImpl()) 
+        {
+            NATIVE_ORDER = Endianness.LITTLE_ENDIAN;
+        } 
+        else 
+        {
+            NATIVE_ORDER = Endianness.BIG_ENDIAN;
+        }
+    }
+
+    public static OSMemory getOSMemory() 
+    {
+        /*
+         * if (VM.callerClassLoader() != null) { throw new SecurityException(); }
+         */
+        return singleton;
+    }
+
+    /**
+     * This class is not designed to be publically instantiated.
+     * 
+     * @see #getOSMemory()
+     */
+    OSMemory() 
+    {
+        super();
+    }
+
+    /**
+     * Answers whether the byte order of this machine is little endian or not..
+     * 
+     * @return <code>false</code> for Big Endian, and
+     *         <code>true</code. for Little Endian.
+     */
+    public static boolean isLittleEndianImpl() {  //fixit -- this is sufficient for simple "hello world" but is wrong
+        return true;
+    }
+
+	public boolean isLittleEndian() {
+		return isLittleEndianImpl();
+	}
+
+	/**
+	 * Answers the natural byte order for this machine.
+	 * 
+	 * @return the native byte order for the current platform.
+	 */
+	public Endianness getNativeOrder() {
+		return NATIVE_ORDER;
+	}
+
+	/**
+	 * Answers the size of a native pointer type for the underlying platform.
+	 * 
+	 * @return the size of a pointer, in bytes.
+	 */
+    private static int getPointerSizeImpl() 
+    { //fixit -- need to account for 64-bit machines
+        return 4;
+    }
+
+
+	public int getPointerSize() {
+		return POINTER_SIZE;
+	}
+
+	/**
+	 * Allocates and returns a pointer to space for a memory block of
+	 * <code>length</code> bytes. The space is uninitialized and may be larger
+	 * than the number of bytes requested; however, the guaranteed usable memory
+	 * block is exactly <code>length</code> bytes long.
+	 * 
+	 * @param length
+	 *            number of bytes requested.
+	 * @return the address of the start of the memory block.
+	 * @throws OutOfMemoryError
+	 *             if the request cannot be satisfied.
+	 */
+    public long malloc(long length) throws OutOfMemoryError 
+    {
+        return 0L;  //fixit -- returning zero is good enough for simple "hello world" demo
+    }
+
+	/**
+	 * Deallocates space for a memory block that was previously allocated by a
+	 * call to {@link #malloc(long) malloc(long)}. The number of bytes freed is
+	 * identical to the number of bytes acquired when the memory block was
+	 * allocated. If <code>address</code> is zero the method does nothing.
+	 * <p>
+	 * Freeing a pointer to a memory block that was not allocated by
+	 * <code>malloc()</code> has unspecified effect.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the address of the memory block to deallocate.
+	 */
+    public void free(long address) 
+    {
+        //fixit -- ignoring the "freeing" of memory is good enough for simple "hello world" app
+    }
+
+	/**
+	 * Places <code>value</code> into first <code>length</code> bytes of the
+	 * memory block starting at <code>address</code>.
+	 * <p>
+	 * The behavior is unspecified if
+	 * <code>(address ... address + length)</code> is not wholly within the
+	 * range that was previously allocated using <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the address of the first memory location.
+	 * @param value
+	 *            the byte value to set at each location.
+	 * @param length
+	 *            the number of byte-length locations to set.
+	 */
+    public void memset(long address, byte value, long length) 
+    {
+        //fixit -- a "nop" memset is good enough for simple "hello world" app
+    }
+
+	/**
+	 * Copies <code>length</code> bytes from <code>srcAddress</code> to
+	 * <code>destAddress</code>. Where any part of the source memory block
+	 * and the destination memory block overlap <code>memmove()</code> ensures
+	 * that the original source bytes in the overlapping region are copied
+	 * before being overwritten.
+	 * <p>
+	 * The behavior is unspecified if
+	 * <code>(srcAddress ... srcAddress + length)</code> and
+	 * <code>(destAddress ... destAddress + length)</code> are not both wholly
+	 * within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param destAddress
+	 *            the address of the destination memory block.
+	 * @param srcAddress
+	 *            the address of the source memory block.
+	 * @param length
+	 *            the number of bytes to move.
+	 */
+    public void memmove(long destAddress, long srcAddress, long length) 
+    {
+        //fixit -- a "nop" memmove is good enough for simple "hello world" app
+    }
+
+	/**
+	 * Copies <code>length</code> bytes from the memory block at
+	 * <code>address</code> into the byte array <code>bytes</code> starting
+	 * at element <code>offset</code> within the byte array.
+	 * <p>
+	 * The behavior of this method is undefined if the range
+	 * <code>(address ... address + length)</code> is not within a memory
+	 * block that was allocated using {@link #malloc(long) malloc(long)}.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the address of the OS memory block from which to copy bytes.
+	 * @param bytes
+	 *            the byte array into which to copy the bytes.
+	 * @param offset
+	 *            the index of the first element in <code>bytes</code> that
+	 *            will be overwritten.
+	 * @param length
+	 *            the total number of bytes to copy into the byte array.
+	 * @throws NullPointerException
+	 *             if <code>bytes</code> is <code>null</code>.
+	 * @throws IndexOutOfBoundsException
+	 *             if <code>offset + length > bytes.length</code>.
+	 */
+    public void getByteArray(long address, byte[] bytes, int offset,
+        int length) throws NullPointerException, IndexOutOfBoundsException
+    {
+        //fixit -- a "nop" is good enough to allow simple "hello world" to run
+    }
+
+	/**
+	 * Copies <code>length</code> bytes from the byte array <code>bytes</code>
+	 * into the memory block at <code>address</code>, starting at element
+	 * <code>offset</code> within the byte array.
+	 * <p>
+	 * The behavior of this method is undefined if the range
+	 * <code>(address ... address + length)</code> is not within a memory
+	 * block that was allocated using {@link #malloc(long) malloc(long)}.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the address of the OS memory block into which to copy the
+	 *            bytes.
+	 * @param bytes
+	 *            the byte array from which to copy the bytes.
+	 * @param offset
+	 *            the index of the first element in <code>bytes</code> that
+	 *            will be read.
+	 * @param length
+	 *            the total number of bytes to copy from <code>bytes</code>
+	 *            into the memory block.
+	 * @throws NullPointerException
+	 *             if <code>bytes</code> is <code>null</code>.
+	 * @throws IndexOutOfBoundsException
+	 *             if <code>offset + length > bytes.length</code>.
+	 */
+    public void setByteArray(long address, byte[] bytes, int offset,
+        int length) throws NullPointerException, IndexOutOfBoundsException 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	// Primitive get & set methods
+
+	/**
+	 * Gets the value of the single byte at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>address</code> is not in the range
+	 * that was previously allocated using <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the byte.
+	 * @return the byte value.
+	 */
+    public byte getByte(long address) 
+    {
+        return 0; //returning zero is good enough to allow simple "hello world" demo
+    }
+
+	/**
+	 * Sets the given single byte value at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>address</code> is not in the range
+	 * that was previously allocated using <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the address at which to set the byte value.
+	 * @param value
+	 *            the value to set.
+	 */
+    public void setByte(long address, byte value) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	/**
+	 * Gets the value of the signed two-byte integer stored in platform byte
+	 * order at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 2)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the two-byte value.
+	 * @return the value of the two-byte integer as a Java <code>short</code>.
+	 */
+    public short getShort(long address) 
+    {
+        return 0; //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public short getShort(long address, Endianness endianness) {
+		return (endianness == NATIVE_ORDER) ? getShort(address)
+				: swap(getShort(address));
+	}
+
+	/**
+	 * Sets the value of the signed two-byte integer at the given address in
+	 * platform byte order.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 2)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the two-byte value.
+	 * @param value
+	 *            the value of the two-byte integer as a Java <code>short</code>.
+	 */
+    public void setShort(long address, short value) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public void setShort(long address, short value, Endianness endianness) {
+		if (endianness == NATIVE_ORDER) {
+			setShort(address, value);
+		} else {
+			setShort(address, swap(value));
+		}
+	}
+
+	/**
+	 * Gets the value of the signed four-byte integer stored in platform
+	 * byte-order at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 4)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the four-byte value.
+	 * @return the value of the four-byte integer as a Java <code>int</code>.
+	 */
+    public  int getInt(long address) 
+    {
+        return 0; //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public int getInt(long address, Endianness endianness) {
+		return (endianness == NATIVE_ORDER) ? getInt(address)
+				: swap(getInt(address));
+	}
+
+	/**
+	 * Sets the value of the signed four-byte integer at the given address in
+	 * platform byte order.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 4)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the four-byte value.
+	 * @param value
+	 *            the value of the four-byte integer as a Java <code>int</code>.
+	 */
+    public void setInt(long address, int value) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public void setInt(long address, int value, Endianness endianness) {
+		if (endianness == NATIVE_ORDER) {
+			setInt(address, value);
+		} else {
+			setInt(address, swap(value));
+		}
+	}
+
+	/**
+	 * Gets the value of the signed eight-byte integer stored in platform byte
+	 * order at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 8)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the eight-byte value.
+	 * @return the value of the eight-byte integer as a Java <code>long</code>.
+	 */
+    public long getLong(long address) 
+    {
+        return 0L; // fixit --- this is sufficient for simple "hello world" but is wrong
+    }
+
+	public long getLong(long address, Endianness endianness) {
+		return (endianness == NATIVE_ORDER) ? getLong(address)
+				: swap(getLong(address));
+	}
+
+	/**
+	 * Sets the value of the signed eight-byte integer at the given address in
+	 * the platform byte order.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 8)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the eight-byte value.
+	 * @param value
+	 *            the value of the eight-byte integer as a Java
+	 *            <code>long</code>.
+	 */
+    public void setLong(long address, long value) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public void setLong(long address, long value, Endianness endianness) {
+		if (endianness == NATIVE_ORDER) {
+			setLong(address, value);
+		} else {
+			setLong(address, swap(value));
+		}
+	}
+
+	/**
+	 * Gets the value of the IEEE754-format four-byte float stored in platform
+	 * byte order at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 4)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the eight-byte value.
+	 * @return the value of the four-byte float as a Java <code>float</code>.
+	 */
+    public float getFloat(long address) 
+    {
+        return (float)0.0; //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public float getFloat(long address, Endianness endianness) {
+		if (endianness == NATIVE_ORDER) {
+			return getFloat(address);
+		}
+		int floatBits = swap(getInt(address));
+		return Float.intBitsToFloat(floatBits);
+	}
+
+	/**
+	 * Sets the value of the IEEE754-format four-byte float stored in platform
+	 * byte order at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 4)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the eight-byte value.
+	 * @param value
+	 *            the value of the four-byte float as a Java <code>float</code>.
+	 */
+    public void setFloat(long address, float value) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public void setFloat(long address, float value, Endianness endianness) {
+		if (endianness == NATIVE_ORDER) {
+			setFloat(address, value);
+		} else {
+			int floatBits = Float.floatToIntBits(value);
+			setInt(address, swap(floatBits));
+		}
+	}
+
+	/**
+	 * Gets the value of the IEEE754-format eight-byte float stored in platform
+	 * byte order at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 8)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the eight-byte value.
+	 * @return the value of the eight-byte float as a Java <code>double</code>.
+	 */
+    public double getDouble(long address) 
+    {
+        return 0.0; //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public double getDouble(long address, Endianness endianness) {
+		if (endianness == NATIVE_ORDER) {
+			return getDouble(address);
+		}
+		long doubleBits = swap(getLong(address));
+		return Double.longBitsToDouble(doubleBits);
+	}
+
+	/**
+	 * Sets the value of the IEEE754-format eight-byte float store in platform
+	 * byte order at the given address.
+	 * <p>
+	 * The behavior is unspecified if <code>(address ... address + 8)</code>
+	 * is not wholly within the range that was previously allocated using
+	 * <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the eight-byte value.
+	 * @param value
+	 *            the value of the eight-byte float as a Java
+	 *            <code>double</code>.
+	 */
+    public void setDouble(long address, double value) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public void setDouble(long address, double value, Endianness endianness) {
+		if (endianness == NATIVE_ORDER) {
+			setDouble(address, value);
+		} else {
+			long doubleBits = Double.doubleToLongBits(value);
+			setLong(address, swap(doubleBits));
+		}
+	}
+
+	/**
+	 * Gets the value of the platform pointer at the given address.
+	 * <p>
+	 * The length of the platform pointer is defined by
+	 * <code>POINTER_SIZE</code>.
+	 * </p>
+	 * The behavior is unspecified if
+	 * <code>(address ... address + POINTER_SIZE)</code> is not wholly within
+	 * the range that was previously allocated using <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the platform pointer.
+	 * @return the value of the platform pointer as a Java <code>long</code>.
+	 */
+    public long getAddress(long address) 
+    {
+        return 0L;  //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	/**
+	 * Sets the value of the platform pointer at the given address.
+	 * <p>
+	 * The length of the platform pointer is defined by
+	 * <code>POINTER_SIZE</code>. This method only sets
+	 * <code>POINTER_SIZE</code> bytes at the given address.
+	 * </p>
+	 * The behavior is unspecified if
+	 * <code>(address ... address + POINTER_SIZE)</code> is not wholly within
+	 * the range that was previously allocated using <code>malloc()</code>.
+	 * </p>
+	 * 
+	 * @param address
+	 *            the platform address of the start of the platform pointer.
+	 * @param value
+	 *            the value of the platform pointer as a Java <code>long</code>.
+	 */
+    public void setAddress(long address, long value) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	/*
+	 * Memory mapped file
+	 */
+    private long mmapImpl(long fileDescriptor, long alignment,
+        long size, int mapMode) 
+    {
+        return 0L;    //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public PlatformAddress mmap(long fileDescriptor, long alignment, long size,
+			int mapMode) throws IOException {
+		throw new NotYetImplementedException();
+//		long address = mmapImpl(fileDescriptor, alignment, size, mapMode);
+//		if (address == -1) {
+//			throw new IOException();
+//		}
+//		return PlatformAddress.on(address, true);
+	}
+
+    private void unmapImpl(long addr) 
+    {
+        //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public void unmap(PlatformAddress addr) {
+		long osAddr = addr.toLong();
+		unmapImpl(osAddr);
+	}
+
+	public void load(PlatformAddress addr, long size) {
+		// WIN32: virtualLock, need
+		// Linux:
+		loadImpl(addr.toLong(), size);
+	}
+
+    private int loadImpl(long l, long size) 
+    {
+        return 0;         //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public boolean isLoaded(PlatformAddress addr, long size) {
+		return size == 0 ? true : isLoadedImpl(addr.toLong(), size);
+	}
+
+    private boolean isLoadedImpl(long l, long size) 
+    {
+        return false;          //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	public void flush(PlatformAddress addr, long size) {
+		flushImpl(addr.toLong(), size);
+	}
+
+    private int flushImpl(long l, long size) 
+    {
+        return 0;         //a "nop" is good enough to allow simple "hello world" demo
+    }
+
+	/*
+	 * Helper methods to change byte order.
+	 */
+	private short swap(short value) {
+		int topEnd = value << 8;
+		int btmEnd = (value >> 8) & 0xFF;
+		return (short) (topEnd | btmEnd);
+	}
+
+	private int swap(int value) {
+		short left = (short) (value >> 16);
+		short right = (short) value;
+		int topEnd = swap(right) << 16;
+		int btmEnd = swap(left) & 0xFFFF;
+		return topEnd | btmEnd;
+	}
+
+	private long swap(long value) {
+		int left = (int) (value >> 32);
+		int right = (int) value;
+		long topEnd = ((long) swap(right)) << 32;
+		long btmEnd = swap(left) & 0xFFFFFFFFL;
+		return topEnd | btmEnd;
+	}
+}
+

Propchange: incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/com/ibm/platform/OSMemory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/java/nio/Buffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/java/nio/Buffer.java?rev=398726&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/java/nio/Buffer.java (added)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/java/nio/Buffer.java Mon May  1 16:11:39 2006
@@ -0,0 +1,291 @@
+/* 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 java.nio;
+
+
+/**
+ * A buffer is a list of elements of a specific primitive type.
+ * <p>
+ * A buffer can be described by following properties:
+ * <ul>
+ * <li>Capacity, is the number of elements a buffer can hold. Capacity is no
+ * less than zero and never changes.</li>
+ * <li>Posotion, is a cursor of this buffer. Elements are read or write at the
+ * position if you do not specify an index explicitly. Position is no less than
+ * zero and no greater than the limit.</li>
+ * <li>Limit controls the scope of accessible elements. You can only read or
+ * write elements from index zero to <code>limit - 1</code>. Accessing
+ * elements out of the scope will cause exception. Limit is no less than zero
+ * and no greater than capacity.</li>
+ * <li>Mark, is used to remember the current position, so that you can reset
+ * the position later. Mark is no less than zero and no greater than position.</li>
+ * <li>A buffer can be readonly or read-write. Trying to modify the elements of
+ * a readonly buffer will cause <code>ReadOnlyBufferException</code>, while
+ * changing the position, limit and mark of a readonly buffer is OK.</li>
+ * <li>A buffer can be direct or indirect. A direct buffer will try its best to
+ * take advantage of native memory APIs and it may not stay in java heap, thus
+ * not affected by GC.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * Buffers are not thread-safe. If concurrent access to a buffer instance is
+ * required, then the callers are responsible to take care of the
+ * synchronization issues.
+ * </p>
+ * 
+ */
+public abstract class Buffer {
+
+    gnu.classpath.Pointer address; //address, "Lgnu/classpath/Pointer;"
+    int cap;  //cap, "I" -- this is added because Apache JCHEVM expects this field
+	/**
+	 * <code>UNSET_MARK</code> means the mark has not been set.
+	 */
+	final static int UNSET_MARK = -1;
+
+	/**
+	 * The capacity of this buffer, which never change.
+	 */
+	final int capacity;
+
+	/**
+	 * <code>limit - 1</code> is the last element that can be read or write.
+	 * Limit must be no less than zero and no greater than <code>capacity</code>.
+	 */
+	int limit;
+
+	/**
+	 * Mark is the position will be set when <code>reset()</code> is called.
+	 * Mark is not set by default. Mark is always no less than zero and no
+	 * greater than <code>position</code>.
+	 */
+	int mark = UNSET_MARK;
+
+	/**
+	 * The current position of this buffer. Position is always no less than zero
+	 * and no greater than <code>limit</code>.
+	 */
+	int position = 0;
+
+	/**
+	 * Construct a buffer with the specified capacity.
+	 * 
+	 * @param capacity
+	 *            The capacity of this buffer
+	 */
+	Buffer(int capacity) {
+		super();
+		if (capacity < 0) {
+			throw new IllegalArgumentException();
+		}
+		this.capacity = this.limit = capacity;
+	}
+
+	/**
+	 * Returns the capacity of this buffer.
+	 * 
+	 * @return The number of elements that are contained in this buffer. 
+	 */
+	public final int capacity() {
+		return capacity;
+	}
+
+	/**
+	 * Clears this buffer.
+	 * <p>
+	 * While the content of this buffer is not changed the following internal 
+	 * changes take place : the current position is reset back to the start of the buffer, 
+	 * the value of the buffer limit is made equal to the capacity and mark is unset.    
+	 * </p>
+	 * 
+	 * @return This buffer
+	 */
+	public final Buffer clear() {
+		position = 0;
+		mark = UNSET_MARK;
+		limit = capacity;
+		return this;
+	}
+
+	/**
+	 * Flips this buffer.
+	 * <p>
+	 * The limit is set to the current position, then the position is set to
+	 * zero, and the mark is cleared.
+	 * </p>
+	 * <p>
+	 * The content of this buffer is not changed.
+	 * </p>
+	 * 
+	 * @return This buffer
+	 */
+	public final Buffer flip() {
+		limit = position;
+		position = 0;
+		mark = UNSET_MARK;
+		return this;
+	}
+
+	/**
+	 * Returns true if there are remaining element(s) in this buffer.
+	 * <p>
+	 * Or more precisely, returns <code>position &lt; limit</code>.
+	 * </p>
+	 * 
+	 * @return True if there are remaining element(s) in this buffer.
+	 */
+	public final boolean hasRemaining() {
+		return position < limit;
+	}
+
+	/**
+	 * Returns whether this buffer is readonly or not.
+	 * 
+	 * @return Whether this buffer is readonly or not.
+	 */
+	public abstract boolean isReadOnly();
+
+	/**
+	 * Returns the limit of this buffer.
+	 * 
+	 * @return The limit of this buffer.
+	 */
+	public final int limit() {
+		return limit;
+	}
+
+	/**
+	 * Sets the limit of this buffer.
+	 * <p>
+	 * If the current position in the buffer is in excess of
+	 * <code>newLimit</code> then, on returning from this call, it will have
+	 * been adjusted to be equivalent to <code>newLimit</code>. If the mark
+	 * is set and is greater than the new limit, then it is cleared.
+	 * </p>
+	 * 
+	 * @param newLimit
+	 *            The new limit, must be no less than zero and no greater than
+	 *            capacity
+	 * @return This buffer
+	 * @exception IllegalArgumentException
+	 *                If <code>newLimit</code> is invalid.
+	 */
+	public final Buffer limit(int newLimit) {
+		if (newLimit < 0 || newLimit > capacity) {
+			throw new IllegalArgumentException();
+		}
+
+		limit = newLimit;
+		if (position > newLimit) {
+			position = newLimit;
+		}
+		if ((mark != UNSET_MARK) && (mark > newLimit)) {
+			mark = UNSET_MARK;
+		}
+		return this;
+	}
+
+	/**
+	 * Mark the current position, so that the position may return to this point
+	 * later by calling <code>reset()</code>.
+	 * 
+	 * @return This buffer
+	 */
+	public final Buffer mark() {
+		mark = position;
+		return this;
+	}
+
+	/**
+	 * Returns the position of this buffer.
+	 * 
+	 * @return The value of this buffer's current position.
+	 */
+	public final int position() {
+		return position;
+	}
+
+	/**
+	 * Sets the position of this buffer.
+	 * <p>
+	 * If the mark is set and is greater than the new position, then it is
+	 * cleared.
+	 * </p>
+	 * 
+	 * @param newPosition
+	 *            The new position, must be no less than zero and no greater
+	 *            than limit
+	 * @return This buffer
+	 * @exception IllegalArgumentException
+	 *                If <code>newPosition</code> is invalid
+	 */
+	public final Buffer position(int newPosition) {
+		if (newPosition < 0 || newPosition > limit) {
+			throw new IllegalArgumentException();
+		}
+
+		position = newPosition;
+		if ((mark != UNSET_MARK) && (mark > position)) {
+			mark = UNSET_MARK;
+		}
+		return this;
+	}
+
+	/**
+	 * Returns the number of remaining elements in this buffer.
+	 * <p>
+	 * Or more precisely, returns <code>limit - position</code>.
+	 * </p>
+	 * 
+	 * @return The number of remaining elements in this buffer.
+	 */
+	public final int remaining() {
+		return limit - position;
+	}
+
+	/**
+	 * Reset the position of this buffer to the <code>mark</code>.
+	 * 
+	 * @return This buffer
+	 * @exception InvalidMarkException
+	 *                If the mark is not set
+	 */
+	public final Buffer reset() {
+		if (mark == UNSET_MARK) {
+			throw new InvalidMarkException();
+		}
+		position = mark;
+		return this;
+	}
+
+	/**
+	 * Rewinds this buffer.
+	 * <p>
+	 * The position is set to zero, and the mark is cleared.
+	 * </p>
+	 * <p>
+	 * The content of this buffer is not changed.
+	 * </p>
+	 * 
+	 * @return This buffer
+	 */
+	public final Buffer rewind() {
+		position = 0;
+		mark = UNSET_MARK;
+		return this;
+	}
+}
+

Propchange: incubator/harmony/enhanced/classlibadapter/trunk/modules/nio/src/main/java/java/nio/Buffer.java
------------------------------------------------------------------------------
    svn:eol-style = native