当前位置: 首页>>代码示例>>Java>>正文


Java ObjectStreamConstants.TC_BLOCKDATA属性代码示例

本文整理汇总了Java中java.io.ObjectStreamConstants.TC_BLOCKDATA属性的典型用法代码示例。如果您正苦于以下问题:Java ObjectStreamConstants.TC_BLOCKDATA属性的具体用法?Java ObjectStreamConstants.TC_BLOCKDATA怎么用?Java ObjectStreamConstants.TC_BLOCKDATA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.io.ObjectStreamConstants的用法示例。


在下文中一共展示了ObjectStreamConstants.TC_BLOCKDATA属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: read_blockdata

public BlockData read_blockdata( byte tc, DataInputStream dis ) throws IOException
{
	int size;
	if ( tc == ObjectStreamConstants.TC_BLOCKDATA ) {
		size = dis.readUnsignedByte();
	}
	else if ( tc == ObjectStreamConstants.TC_BLOCKDATALONG ) {
		size = dis.readInt();
	}
	else {
		throw new IOException( "invalid tc value for blockdata: " + hex( tc ) );
	}
	if ( size < 0 ) {
		throw new IOException( "invalid value for blockdata size: " + size );
	}
	byte[] b = new byte[size];
	dis.readFully( b );
	debug( "read blockdata of size " + size );
	return new BlockData( b );
}
 
开发者ID:kartoFlane,项目名称:superluminal2,代码行数:20,代码来源:JDeserialize.java

示例2: handleObjectAnnotation

/*******************
 * Handle an objectAnnotation element, extracting the object endpoint
 * details if found.
 * 
 * @param obj The RMIObject to populate with class names.
 * @param dataStack The remaining data in the ReplyData packet.
 ******************/
private void handleObjectAnnotation(RMIObject obj, LinkedList<Byte> dataStack) throws BaRMIeInvalidReplyDataPacketException {
	byte b;
	
	//Read elements from the stream until a TC_ENDBLOCKDATA element is read
	while((b = dataStack.pop()) != ObjectStreamConstants.TC_ENDBLOCKDATA) {
		//Handle the annotation
		switch(b) {
			//Look for object endpoint details in block data elements
			case ObjectStreamConstants.TC_BLOCKDATA:
				//Push the block type back on to the stack and extract endpoint details if found
				dataStack.push(ObjectStreamConstants.TC_BLOCKDATA);
				this.extractObjectEndpointFromBlockData(obj, dataStack);
				break;
				
			//Skip over object annotations
			case ObjectStreamConstants.TC_OBJECT:
				this.handleNewObjectElement(obj, dataStack);
				break;
				
			//Ignore null annotations...
			case ObjectStreamConstants.TC_NULL:
				break;
				
			//Unknown annotation type
			default:
				throw new BaRMIeInvalidReplyDataPacketException("Unknown classAnnotation element type (0x" + String.format("%02x", b) + ").");
		}
	}
}
 
开发者ID:NickstaDB,项目名称:BaRMIe,代码行数:36,代码来源:RMIReplyDataParser.java

示例3: read_Content

/**
 * <p>
 * Read the next object corresponding to the spec grammar rule "content", and return
 * an object of type content.
 * </p>
 *
 * <p>
 * Usually, there is a 1:1 mapping of content items and returned instances. The
 * one case where this isn't true is when an exception is embedded inside another
 * object. When this is encountered, only the serialized exception object is
 * returned; it's up to the caller to backtrack in order to gather any data from the
 * object that was being serialized when the exception was thrown.
 * </p>
 *
 * @param tc
 *            the last byte read from the stream; it must be one of the TC_* values
 *            within ObjectStreamConstants.*
 * @param dis
 *            the DataInputStream to read from
 * @param blockdata
 *            whether or not to read TC_BLOCKDATA (this is the difference
 *            between spec rules "object" and "content").
 * @return an object representing the last read item from the stream
 * @throws IOException
 *             when a validity or I/O error occurs while reading
 */
public Content read_Content( byte tc, DataInputStream dis, boolean blockdata ) throws IOException
{
	try {
		switch ( tc ) {
			case ObjectStreamConstants.TC_OBJECT:
				return read_newObject( dis );
			case ObjectStreamConstants.TC_CLASS:
				return read_newClass( dis );
			case ObjectStreamConstants.TC_ARRAY:
				return read_newArray( dis );
			case ObjectStreamConstants.TC_STRING:
			case ObjectStreamConstants.TC_LONGSTRING:
				return read_newString( tc, dis );
			case ObjectStreamConstants.TC_ENUM:
				return read_newEnum( dis );
			case ObjectStreamConstants.TC_CLASSDESC:
			case ObjectStreamConstants.TC_PROXYCLASSDESC:
				return handle_newClassDesc( tc, dis );
			case ObjectStreamConstants.TC_REFERENCE:
				return read_prevObject( dis );
			case ObjectStreamConstants.TC_NULL:
				return null;
			case ObjectStreamConstants.TC_EXCEPTION:
				return read_Exception( dis );
			case ObjectStreamConstants.TC_BLOCKDATA:
			case ObjectStreamConstants.TC_BLOCKDATALONG:
				if ( blockdata == false ) {
					throw new IOException( "got a blockdata TC_*, but not allowed here: " + hex( tc ) );
				}
				return read_blockdata( tc, dis );
			default:
				throw new IOException( "unknown content tc byte in stream: " + hex( tc ) );
		}
	}
	catch ( ReadException ere ) {
		return ere.getExceptionObject();
	}
}
 
开发者ID:kartoFlane,项目名称:superluminal2,代码行数:64,代码来源:JDeserialize.java

示例4: extractObjectDetails

/*******************
 * Extract object details from a ReplyData that was captured through the
 * RMI registry proxy.
 * 
 * @param objName The object name bound to the RMI registry for which data is being extracted.
 * @param packetBytes The ReplyData captured from the RMI registry which contains the remote object description.
 * @return An RMIObject describing the remote object.
 ******************/
public RMIObject extractObjectDetails(String objName, ArrayList<Byte> packetBytes) {
	LinkedList<Byte> dataStack;
	RMIObject obj;
	byte b;
	int i;
	
	//Create the RMIObject with the given object name
	obj = new RMIObject(objName);
	
	//Copy the given buffer into a stack for parsing
	dataStack = new LinkedList<Byte>();
	dataStack.addAll(packetBytes);
	
	//Set the 'recordClasses' flag to true so that class descriptions are added to the object description
	this._recordClasses = true;
	
	//Start parsing the object data
	try {
		//Validate the RMI packet type byte
		if(dataStack.peek() != 0x51) { throw new BaRMIeInvalidReplyDataPacketException("The data buffer begins with 0x" + String.format("%02x", dataStack.peek()) + ", which is not a ReplyData packet (0x51 expected)."); }
		dataStack.pop();
		
		//Validate the serialisation header
		if(dataStack.pop() != (byte)0xac || dataStack.pop() != (byte)0xed) { throw new BaRMIeInvalidReplyDataPacketException("The data buffer does not contain the serialisation magic number data."); }
		
		//Validate the serialisation stream version
		if(dataStack.pop() != 0x00 || dataStack.pop() != 0x05) { throw new BaRMIeInvalidReplyDataPacketException("The data buffer does not contain version 5 serialisation data."); }
		
		//Parse the serialisation stream elements to extract class names, annotations, and endpoint details
		while(dataStack.size() > 0) {
			//Get the type of the next stream element
			b = dataStack.pop();
			
			//Process the element accordingly
			switch(b) {
				//Skip over top-level block data elements
				case ObjectStreamConstants.TC_BLOCKDATA:
					//Read the block length
					b = dataStack.pop();
					
					//Skip over the block bytes
					for(i = 0; i < b; ++i) {
						dataStack.pop();
					}
					break;
					
				//Process the returned RMI object
				case ObjectStreamConstants.TC_OBJECT:
					this.handleNewObjectElement(obj, dataStack);
					break;
					
				//Unknown top-level stream element type
				default:
					throw new BaRMIeInvalidReplyDataPacketException("Unknown serialisation stream element (0x" + String.format("%02x", b) + ").");
			}
		}
	} catch(Exception e) {
		//Something went wrong, store the exception in the object element so it can be reviewed
		obj.setParsingException(e);
	}
	
	//Return the RMIObject
	return obj;
}
 
开发者ID:NickstaDB,项目名称:BaRMIe,代码行数:72,代码来源:RMIReplyDataParser.java


注:本文中的java.io.ObjectStreamConstants.TC_BLOCKDATA属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。