nativestream.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 188 行

JAVA
188
字号
/**
 * $Id: NativeStream.java,v 1.4 2004/02/26 10:33:50 epr Exp $
 */

package org.jnode.assembler;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;

import org.jnode.vm.CpuID;
import org.jnode.vm.classmgr.VmType;

public abstract class NativeStream {

    /**
     * Remove all data and references.
     */
    public abstract void clear();
    
	/**
	 * Returns the base address.
	 * @return long
	 */
	public abstract long getBaseAddr();

	/**
	 * Get the length in bytes of valid data
	 * @return The length 
	 */
	public abstract int getLength();

	/**
	 * Return the actual bytes. This array may be longer then getLength()
	 * @return The actual bytes
	 */
	public abstract byte[] getBytes();

	/**
	 * Gets the identification of the CPU for which this stream will produce data.
	 */
	public abstract CpuID getCPUID();
	
	/**
	 * Write my contents to the given stream.
	 * @param os
	 * @throws IOException
	 */
	public abstract void writeTo(OutputStream os) throws IOException;

	/**
	 * Start a new object and write its header.
	 * An ObjectInfo object is returned, on which the <code>markEnd</code>
	 * mehod must be called after all data has been written into the object.
	 * @param cls
	 * @see ObjectInfo
	 * @return The object info for the started object
	 */
	public abstract ObjectInfo startObject(VmType cls);

	/**
	 * Gets an objectref for a given object.
	 * @param key
	 * @return ObjectRef
	 */
	public abstract ObjectRef getObjectRef(Object key);

	/**
	 * Gets all references of objects as instanceof ObjectRef
	 * @return Collection
	 */
	public abstract Collection getObjectRefs();

	/**
	 * Gets all unresolved references of objects as instanceof ObjectRef
	 * @return Collection
	 */
	public abstract Collection getUnresolvedObjectRefs();

	/**
	 * Are there unresolved references?
	 * @return True if there are unsolved references, false otherwise
	 */
	public abstract boolean hasUnresolvedObjectRefs();

	/**
	 * Resolve the given object to the current position.
	 * @param label
	 * @return ObjectRef
	 */
	public abstract ObjectRef setObjectRef(Object label);
	
	/**
	 * Write a reference to the given object
	 * @param object
	 */
	//public abstract void writeObjectRef(Object object);

	/**
	 * Write a 64-bit integer
	 * @param value
	 */
	public abstract void write64(long value);

	/**
	 * Write a 32-bit integer
	 * @param value
	 */
	public abstract void write32(int value);

	/**
	 * Write a 16-bit short
	 * @param value
	 */
	public abstract void write16(int value);

	/**
	 * Write a 8-bit byte
	 * @param value
	 */
	public abstract void write8(int value);

	/**
	 * Write a series of bytes
	 * @param data
	 * @param ofs
	 * @param len
	 */
	public abstract void write(byte[] data, int ofs, int len);

	/**
	 * A wrapper for constructing objects in the native stream.
	 */
	public abstract class ObjectInfo {

		/**
		 * Mark the current location as the end of this object end fixup the objectheader.
		 */
		public abstract void markEnd();
	}

	public abstract class ObjectRef {
		private Object object;

		/**
		 * Create a new instance
		 * @param object
		 */
		public ObjectRef(Object object) {
			this.object = object;
		}

		/**
		 * Gets the object i'm refering to.
		 * @return Object
		 */
		public Object getObject() {
			return object;
		}

		/**
		 * Gets the offset of my object within this stream. This offset is only valid if <code>isResolved() == true</code>.
		 * @return int
		 * @throws UnresolvedObjectRefException
		 */
		public abstract int getOffset()
		throws UnresolvedObjectRefException;

		/**
		 * Has my object been resolved?
		 * @return boolean
		 */
		public abstract boolean isResolved();
		
		/**
		 * Link this objectref to the given objectref. That is, the offset of this
		 * objectref will be set to the offset of the given objectref.
		 * @param objectRef
		 * @throws UnresolvedObjectRefException The given objectref is not resolved.
		 */
		public abstract void link(ObjectRef objectRef)
		throws UnresolvedObjectRefException;
		
		public String toString() {
			return object.toString();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?