示例#1
0
		/// <summary>
		/// Copy the bitmap's pixels into the specified buffer (allocated by the
		/// caller).
		/// </summary>
		/// <remarks>
		/// Copy the bitmap's pixels into the specified buffer (allocated by the
		/// caller). An exception is thrown if the buffer is not large enough to
		/// hold all of the pixels (taking into account the number of bytes per
		/// pixel) or if the Buffer subclass is not one of the support types
		/// (ByteBuffer, ShortBuffer, IntBuffer).
		/// </remarks>
		public void copyPixelsToBuffer (java.nio.Buffer dst)
		{
			int elements = dst.remaining ();
			int shift;
			if (dst is java.nio.ByteBuffer) {
				shift = 0;
			} else {
				if (dst is java.nio.ShortBuffer) {
					shift = 1;
				} else {
					if (dst is java.nio.IntBuffer) {
						shift = 2;
					} else {
						throw new java.lang.RuntimeException ("unsupported Buffer subclass");
					}
				}
			}
			long bufferSize = (long)elements << shift;
			long pixelSize = getByteCount ();
			if (bufferSize < pixelSize) {
				throw new java.lang.RuntimeException ("Buffer not large enough for pixels");
			}
			// FIXME
			// nativeCopyPixelsToBuffer (mNativeBitmap, dst);
			// now update the buffer's position
			int position = dst.position ();
			// FIXME: Needed to add an explicit cast to int.
			position += (int)(pixelSize >> shift);
			dst.position (position);
		}
示例#2
0
		public virtual java.nio.ByteBuffer put(java.nio.ByteBuffer src)
		{
			if (src == this)
			{
				throw new System.ArgumentException("src == this");
			}
			int srcByteCount = src.remaining();
			if (srcByteCount > remaining())
			{
				throw new java.nio.BufferOverflowException();
			}
			if (src.isDirect()) {
				throw new System.InvalidOperationException();
			}
			byte[] srcObject = java.nio.NioUtils.unsafeArray(src);
			int srcOffset = src.position();
			if (!src.isDirect())
			{
				srcOffset += java.nio.NioUtils.unsafeArrayOffset(src);
			}
			java.nio.ByteBuffer dst = this;
			if (dst.isDirect()) {
				throw new System.InvalidOperationException();
			}
			byte[] dstObject = java.nio.NioUtils.unsafeArray(dst);
			int dstOffset = dst.position();
			if (!dst.isDirect())
			{
				dstOffset += java.nio.NioUtils.unsafeArrayOffset(dst);
			}
			System.Array.Copy(srcObject, srcOffset, dstObject, dstOffset, srcByteCount);
			src.position(src.limit());
			dst.position(dst.position() + srcByteCount);
			return this;
		}
示例#3
0
 public static java.lang.Class defineClass2(java.lang.ClassLoader thisClassLoader, string name, java.nio.ByteBuffer bb, int off, int len, java.security.ProtectionDomain pd, string source)
 {
     #if FIRST_PASS
     return null;
     #else
     byte[] buf = new byte[bb.remaining()];
     bb.get(buf);
     return defineClass1(thisClassLoader, name, buf, 0, buf.Length, pd, source);
     #endif
 }
示例#4
0
		/// <summary>
		/// Decodes bytes starting at the current position of the given input buffer,
		/// and writes the equivalent character sequence into the given output buffer
		/// from its current position.
		/// </summary>
		/// <remarks>
		/// Decodes bytes starting at the current position of the given input buffer,
		/// and writes the equivalent character sequence into the given output buffer
		/// from its current position.
		/// <p>
		/// The buffers' position will be changed with the reading and writing
		/// operation, but their limits and marks will be kept intact.
		/// <p>
		/// A <code>CoderResult</code> instance will be returned according to
		/// following rules:
		/// <ul>
		/// <li>
		/// <see cref="CoderResult.OVERFLOW">CoderResult.OVERFLOW</see>
		/// indicates that
		/// even though not all of the input has been processed, the buffer the
		/// output is being written to has reached its capacity. In the event of this
		/// code being returned this method should be called once more with an
		/// <code>out</code> argument that has not already been filled.</li>
		/// <li>
		/// <see cref="CoderResult.UNDERFLOW">CoderResult.UNDERFLOW</see>
		/// indicates that
		/// as many bytes as possible in the input buffer have been decoded. If there
		/// is no further input and no remaining bytes in the input buffer then this
		/// operation may be regarded as complete. Otherwise, this method should be
		/// called once more with additional input.</li>
		/// <li>A
		/// <see cref="CoderResult.malformedForLength(int)">malformed input</see>
		/// result
		/// indicates that some malformed input error has been encountered, and the
		/// erroneous bytes start at the input buffer's position and their number can
		/// be got by result's
		/// <see cref="CoderResult.length()">length</see>
		/// . This kind of
		/// result can be returned only if the malformed action is
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// . </li>
		/// <li>A
		/// <see cref="CoderResult.unmappableForLength(int)">unmappable character</see>
		/// result indicates that some unmappable character error has been
		/// encountered, and the erroneous bytes start at the input buffer's position
		/// and their number can be got by result's
		/// <see cref="CoderResult.length()">length</see>
		/// . This kind of result can be returned
		/// only if the unmappable character action is
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// . </li>
		/// </ul>
		/// <p>
		/// The <code>endOfInput</code> parameter indicates that the invoker cannot
		/// provide further input. This parameter is true if and only if the bytes in
		/// current input buffer are all inputs for this decoding operation. Note
		/// that it is common and won't cause an error if the invoker sets false and
		/// then can't provide more input, while it may cause an error if the invoker
		/// always sets true in several consecutive invocations. This would make the
		/// remaining input to be treated as malformed input.
		/// <p>
		/// This method invokes the
		/// <see cref="decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer)">decodeLoop</see>
		/// method to
		/// implement the basic decode logic for a specific charset.
		/// </remarks>
		/// <param name="in">the input buffer.</param>
		/// <param name="out">the output buffer.</param>
		/// <param name="endOfInput">true if all the input characters have been provided.</param>
		/// <returns>
		/// a <code>CoderResult</code> instance which indicates the reason
		/// of termination.
		/// </returns>
		/// <exception cref="System.InvalidOperationException">
		/// if decoding has started or no more input is needed in this
		/// decoding progress.
		/// </exception>
		/// <exception cref="CoderMalfunctionError">
		/// if the
		/// <see cref="decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer)">decodeLoop</see>
		/// method threw an <code>BufferUnderflowException</code> or
		/// <code>BufferOverflowException</code>.
		/// </exception>
		public java.nio.charset.CoderResult decode(java.nio.ByteBuffer @in, java.nio.CharBuffer
			 @out, bool endOfInput)
		{
			if ((status == FLUSH) || (!endOfInput && status == END))
			{
				throw new System.InvalidOperationException();
			}
			java.nio.charset.CoderResult result = null;
			// begin to decode
			while (true)
			{
				java.nio.charset.CodingErrorAction action = null;
				try
				{
					result = decodeLoop(@in, @out);
				}
				catch (java.nio.BufferOverflowException ex)
				{
					// unexpected exception
					throw new java.nio.charset.CoderMalfunctionError(ex);
				}
				catch (java.nio.BufferUnderflowException ex)
				{
					// unexpected exception
					throw new java.nio.charset.CoderMalfunctionError(ex);
				}
				if (result.isUnderflow())
				{
					int remaining = @in.remaining();
					status = endOfInput ? END : ONGOING;
					if (endOfInput && remaining > 0)
					{
						result = java.nio.charset.CoderResult.malformedForLength(remaining);
					}
					else
					{
						return result;
					}
				}
				if (result.isOverflow())
				{
					return result;
				}
				// set coding error handle action
				action = _malformedInputAction;
				if (result.isUnmappable())
				{
					action = _unmappableCharacterAction;
				}
				// If the action is IGNORE or REPLACE, we should continue decoding.
				if (action == java.nio.charset.CodingErrorAction.REPLACE)
				{
					if (@out.remaining() < replacementChars.Length)
					{
						return java.nio.charset.CoderResult.OVERFLOW;
					}
					@out.put(replacementChars);
				}
				else
				{
					if (action != java.nio.charset.CodingErrorAction.IGNORE)
					{
						return result;
					}
				}
				@in.position(@in.position() + result.length());
			}
		}
示例#5
0
		/// <summary>This is a facade method for the decoding operation.</summary>
		/// <remarks>
		/// This is a facade method for the decoding operation.
		/// <p>
		/// This method decodes the remaining byte sequence of the given byte buffer
		/// into a new character buffer. This method performs a complete decoding
		/// operation, resets at first, then decodes, and flushes at last.
		/// <p>
		/// This method should not be invoked while another
		/// <code>decode</code>
		/// operation
		/// is ongoing.
		/// </remarks>
		/// <param name="in">the input buffer.</param>
		/// <returns>
		/// a new <code>CharBuffer</code> containing the the characters
		/// produced by this decoding operation. The buffer's limit will be
		/// the position of the last character in the buffer, and the
		/// position will be zero.
		/// </returns>
		/// <exception cref="System.InvalidOperationException">if another decoding operation is ongoing.
		/// 	</exception>
		/// <exception cref="MalformedInputException">
		/// if an illegal input byte sequence for this charset was
		/// encountered, and the action for malformed error is
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// </exception>
		/// <exception cref="UnmappableCharacterException">
		/// if a legal but unmappable input byte sequence for this
		/// charset was encountered, and the action for unmappable
		/// character error is
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// .
		/// Unmappable means the byte sequence at the input buffer's
		/// current position cannot be mapped to a Unicode character
		/// sequence.
		/// </exception>
		/// <exception cref="CharacterCodingException">if another exception happened during the decode operation.
		/// 	</exception>
		/// <exception cref="java.nio.charset.CharacterCodingException"></exception>
		public java.nio.CharBuffer decode(java.nio.ByteBuffer @in)
		{
			reset();
			int length = (int)(@in.remaining() * _averageCharsPerByte);
			java.nio.CharBuffer output = java.nio.CharBuffer.allocate(length);
			java.nio.charset.CoderResult result = null;
			while (true)
			{
				result = decode(@in, output, false);
				checkCoderResult(result);
				if (result.isUnderflow())
				{
					break;
				}
				else
				{
					if (result.isOverflow())
					{
						output = allocateMore(output);
					}
				}
			}
			result = decode(@in, output, true);
			checkCoderResult(result);
			while (true)
			{
				result = flush(output);
				checkCoderResult(result);
				if (result.isOverflow())
				{
					output = allocateMore(output);
				}
				else
				{
					break;
				}
			}
			output.flip();
			status = FLUSH;
			return output;
		}
示例#6
0
		/// <summary>
		/// Encodes characters starting at the current position of the given input
		/// buffer, and writes the equivalent byte sequence into the given output
		/// buffer from its current position.
		/// </summary>
		/// <remarks>
		/// Encodes characters starting at the current position of the given input
		/// buffer, and writes the equivalent byte sequence into the given output
		/// buffer from its current position.
		/// <p>
		/// The buffers' position will be changed with the reading and writing
		/// operation, but their limits and marks will be kept intact.
		/// <p>
		/// A <code>CoderResult</code> instance will be returned according to
		/// following rules:
		/// <ul>
		/// <li>A
		/// <see cref="CoderResult.malformedForLength(int)">malformed input</see>
		/// result
		/// indicates that some malformed input error was encountered, and the
		/// erroneous characters start at the input buffer's position and their
		/// number can be got by result's
		/// <see cref="CoderResult.length()">length</see>
		/// . This
		/// kind of result can be returned only if the malformed action is
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// .</li>
		/// <li>
		/// <see cref="CoderResult.UNDERFLOW">CoderResult.UNDERFLOW</see>
		/// indicates that
		/// as many characters as possible in the input buffer have been encoded. If
		/// there is no further input and no characters left in the input buffer then
		/// this task is complete. If this is not the case then the client should
		/// call this method again supplying some more input characters.</li>
		/// <li>
		/// <see cref="CoderResult.OVERFLOW">CoderResult.OVERFLOW</see>
		/// indicates that the
		/// output buffer has been filled, while there are still some characters
		/// remaining in the input buffer. This method should be invoked again with a
		/// non-full output buffer.</li>
		/// <li>A
		/// <see cref="CoderResult.unmappableForLength(int)">unmappable character</see>
		/// result indicates that some unmappable character error was encountered,
		/// and the erroneous characters start at the input buffer's position and
		/// their number can be got by result's
		/// <see cref="CoderResult.length()">length</see>
		/// .
		/// This kind of result can be returned only on
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// .</li>
		/// </ul>
		/// <p>
		/// The <code>endOfInput</code> parameter indicates if the invoker can
		/// provider further input. This parameter is true if and only if the
		/// characters in the current input buffer are all inputs for this encoding
		/// operation. Note that it is common and won't cause an error if the invoker
		/// sets false and then has no more input available, while it may cause an
		/// error if the invoker always sets true in several consecutive invocations.
		/// This would make the remaining input to be treated as malformed input.
		/// input.
		/// <p>
		/// This method invokes the
		/// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see>
		/// method to
		/// implement the basic encode logic for a specific charset.
		/// </remarks>
		/// <param name="in">the input buffer.</param>
		/// <param name="out">the output buffer.</param>
		/// <param name="endOfInput">true if all the input characters have been provided.</param>
		/// <returns>a <code>CoderResult</code> instance indicating the result.</returns>
		/// <exception cref="System.InvalidOperationException">
		/// if the encoding operation has already started or no more
		/// input is needed in this encoding process.
		/// </exception>
		/// <exception cref="CoderMalfunctionError">
		/// If the
		/// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see>
		/// method threw an <code>BufferUnderflowException</code> or
		/// <code>BufferUnderflowException</code>.
		/// </exception>
		public java.nio.charset.CoderResult encode(java.nio.CharBuffer @in, java.nio.ByteBuffer
			 @out, bool endOfInput)
		{
			// If the previous step is encode(CharBuffer), then no more input is needed
			// thus endOfInput should not be false
			if (status == READY && finished && !endOfInput)
			{
				throw new System.InvalidOperationException();
			}
			if ((status == FLUSH) || (!endOfInput && status == END))
			{
				throw new System.InvalidOperationException();
			}
			java.nio.charset.CoderResult result;
			while (true)
			{
				try
				{
					result = encodeLoop(@in, @out);
				}
				catch (java.nio.BufferOverflowException e)
				{
					throw new java.nio.charset.CoderMalfunctionError(e);
				}
				catch (java.nio.BufferUnderflowException e)
				{
					throw new java.nio.charset.CoderMalfunctionError(e);
				}
				if (result == java.nio.charset.CoderResult.UNDERFLOW)
				{
					status = endOfInput ? END : ONGOING;
					if (endOfInput)
					{
						int remaining = @in.remaining();
						if (remaining > 0)
						{
							result = java.nio.charset.CoderResult.malformedForLength(remaining);
						}
						else
						{
							return result;
						}
					}
					else
					{
						return result;
					}
				}
				else
				{
					if (result == java.nio.charset.CoderResult.OVERFLOW)
					{
						status = endOfInput ? END : ONGOING;
						return result;
					}
				}
				java.nio.charset.CodingErrorAction action = _malformedInputAction;
				if (result.isUnmappable())
				{
					action = _unmappableCharacterAction;
				}
				// If the action is IGNORE or REPLACE, we should continue
				// encoding.
				if (action == java.nio.charset.CodingErrorAction.REPLACE)
				{
					if (@out.remaining() < replacementBytes.Length)
					{
						return java.nio.charset.CoderResult.OVERFLOW;
					}
					@out.put(replacementBytes);
				}
				else
				{
					if (action != java.nio.charset.CodingErrorAction.IGNORE)
					{
						return result;
					}
				}
				@in.position(@in.position() + result.length());
			}
		}
示例#7
0
		/// <summary>This is a facade method for the encoding operation.</summary>
		/// <remarks>
		/// This is a facade method for the encoding operation.
		/// <p>
		/// This method encodes the remaining character sequence of the given
		/// character buffer into a new byte buffer. This method performs a complete
		/// encoding operation, resets at first, then encodes, and flushes at last.
		/// <p>
		/// This method should not be invoked if another encode operation is ongoing.
		/// </remarks>
		/// <param name="in">the input buffer.</param>
		/// <returns>
		/// a new <code>ByteBuffer</code> containing the bytes produced by
		/// this encoding operation. The buffer's limit will be the position
		/// of the last byte in the buffer, and the position will be zero.
		/// </returns>
		/// <exception cref="System.InvalidOperationException">if another encoding operation is ongoing.
		/// 	</exception>
		/// <exception cref="MalformedInputException">
		/// if an illegal input character sequence for this charset is
		/// encountered, and the action for malformed error is
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// </exception>
		/// <exception cref="UnmappableCharacterException">
		/// if a legal but unmappable input character sequence for this
		/// charset is encountered, and the action for unmappable
		/// character error is
		/// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
		/// .
		/// Unmappable means the Unicode character sequence at the input
		/// buffer's current position cannot be mapped to a equivalent
		/// byte sequence.
		/// </exception>
		/// <exception cref="CharacterCodingException">if other exception happened during the encode operation.
		/// 	</exception>
		/// <exception cref="java.nio.charset.CharacterCodingException"></exception>
		public java.nio.ByteBuffer encode(java.nio.CharBuffer @in)
		{
			if (@in.remaining() == 0)
			{
				return java.nio.ByteBuffer.allocate(0);
			}
			reset();
			int length = (int)(@in.remaining() * _averageBytesPerChar);
			java.nio.ByteBuffer output = java.nio.ByteBuffer.allocate(length);
			java.nio.charset.CoderResult result = null;
			while (true)
			{
				result = encode(@in, output, false);
				if (result == java.nio.charset.CoderResult.UNDERFLOW)
				{
					break;
				}
				else
				{
					if (result == java.nio.charset.CoderResult.OVERFLOW)
					{
						output = allocateMore(output);
						continue;
					}
				}
				checkCoderResult(result);
			}
			result = encode(@in, output, true);
			checkCoderResult(result);
			while (true)
			{
				result = flush(output);
				if (result == java.nio.charset.CoderResult.UNDERFLOW)
				{
					output.flip();
					break;
				}
				else
				{
					if (result == java.nio.charset.CoderResult.OVERFLOW)
					{
						output = allocateMore(output);
						continue;
					}
				}
				checkCoderResult(result);
				output.flip();
				if (result.isMalformed())
				{
					throw new java.nio.charset.MalformedInputException(result.length());
				}
				else
				{
					if (result.isUnmappable())
					{
						throw new java.nio.charset.UnmappableCharacterException(result.length());
					}
				}
				break;
			}
			status = READY;
			finished = true;
			return output;
		}