view src/org/eclipse/jetty/io/View.java @ 1042:a62193321d6a

remove Buffer.reset()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Nov 2016 01:03:25 -0600
parents 35e3c864d7a7
children dd71a59fcf72
line wrap: on
line source

//
//  ========================================================================
//  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

package org.eclipse.jetty.io;

/**
 * A View on another buffer.  Allows operations that do not change the _content or
 * indexes of the backing buffer.
 * 
 * 
 * 
 */
final class View extends AbstractBuffer
{
	private Buffer _buffer;

	View(Buffer buffer)
	{
		super( buffer.isReadOnly()?READONLY:READWRITE );
		_buffer = buffer.buffer();
		setGetIndex(0);
		setPutIndex(buffer.putIndex());
		setGetIndex(buffer.getIndex());
		setMarkIndex(buffer.markIndex());
	}


	@Override
	public byte[] array()
	{
		return _buffer.array();
	}

	@Override
	public Buffer buffer()
	{
		return _buffer.buffer();
	}

	@Override
	public int capacity()
	{
		return _buffer.capacity();
	}

	@Override
	public void clear()
	{
		setMarkIndex(-1);
		setGetIndex(0);
		setPutIndex(_buffer.getIndex());
		setGetIndex(_buffer.getIndex());
	}

	@Override
	public void compact()
	{
		// TODO
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		return  this==obj ||((obj instanceof Buffer)&& obj.equals(this)) || super.equals(obj);
	}

	@Override
	public boolean isReadOnly()
	{
		return _buffer.isReadOnly();
	}

	@Override
	public byte peek(int index)
	{
		return _buffer.peek(index);
	}

	@Override
	public int peek(int index, byte[] b, int offset, int length)
	{
		return _buffer.peek(index,b,offset,length);
	}

	@Override
	public int poke(int index, Buffer src)
	{
		return _buffer.poke(index,src); 
	}

	@Override
	public void poke(int index, byte b)
	{
		_buffer.poke(index,b);
	}

	@Override
	public int poke(int index, byte[] b, int offset, int length)
	{
		return _buffer.poke(index,b,offset,length);
	}
	
	@Override
	public String toString()
	{
		if (_buffer==null)
			return "INVALID";
		return super.toString();
	}
}