⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpinputstream.java

📁 java语言开发的P2P流媒体系统
💻 JAVA
字号:
/* 
 * P2P-Radio - Peer to peer streaming system
 * Project homepage: http://p2p-radio.sourceforge.net/
 * Copyright (C) 2003-2004 Michael Kaufmann <hallo@michael-kaufmann.ch>
 * 
 * ---------------------------------------------------------------------------
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * ---------------------------------------------------------------------------
 */

package p2pradio.io;

import java.io.*;


/**
 * This class is a replacement for java.io.DataInputStream.
 * 
 * It's needed because GNU Classpath's implementation of readLine()
 * is not compatible with Sun's implementation (read the comments
 * in the file DataInputStream.java of GNU Classpath).
 * 
 * This only accepts CRLF and LF line endings.
 * 
 * @author Michael Kaufmann
 */
public class HttpInputStream extends FilterInputStream implements DataInput
{
	protected DataInputStream in;
	
	public HttpInputStream(InputStream inputStream)
	{
		super(inputStream);
		
		if (super.in instanceof DataInputStream)
		{
			in = (DataInputStream) super.in;
		}
		else
		{
			in = new DataInputStream(super.in);
		}
	}
	
	public final void readFully(byte b[]) throws IOException
	{
		in.readFully(b);
	}
	
	public final void readFully(byte b[], int off, int len) throws IOException
	{
		in.readFully(b, off, len);
	}
	
	public final int skipBytes(int n) throws IOException
	{
		return in.skipBytes(n);
	}
	
	public final boolean readBoolean() throws IOException
	{
		return in.readBoolean();
	}
	
	public final byte readByte() throws IOException
	{
		return in.readByte();
	}
	
	public final int readUnsignedByte() throws IOException
	{
		return in.readUnsignedByte();
	}
	
	public final short readShort() throws IOException
	{
		return in.readShort();
	}
	
	public final int readUnsignedShort() throws IOException
	{
		return in.readUnsignedShort();
	}
	
	public final char readChar() throws IOException
	{
		return in.readChar();
	}
	
	public final int readInt() throws IOException
	{
		return in.readInt();
	}
	
	public final long readLong() throws IOException
	{
		return in.readLong();
	}
	
	public final float readFloat() throws IOException
	{
		return in.readFloat();
	}
	
	public final double readDouble() throws IOException
	{
		return in.readDouble();
	}
	
	public final String readUTF() throws IOException
	{
		return in.readUTF();
	}
	
	/**
	 * This method only accepts CRLF and LF line endings in order to
	 * simplify the implementation.
	 * Thus it's not compatible with the contract of DataInput.readLine().
	 */
	public final String readLine() throws IOException
	{
		StringBuffer buffer = new StringBuffer();
		
		while (true)
		{
			int c = in.read();
					
			if (c == -1)	// end of stream
			{
				if (buffer.length() == 0)
				{
					return null;
				}
				else
				{
					return buffer.toString();
				}
			}
				
			char ch = (char) c;
			
			if (ch == '\r')  // CR
			{
				int next_c = in.read();
				char next_ch = (char) next_c;
		
				if (next_ch == '\n')
				{
					break;
				}
				else
				{
					throw new IOException("Line ending is neither CRLF nor LF"); //$NON-NLS-1$
				}
			}
			
			if (ch == '\n')   // LF
			{
				break;
			}
		
			buffer.append(ch);
		}
		
		if (buffer.length() == 0)
		{
			return ""; //$NON-NLS-1$
		}
		else
		{
			return buffer.toString();
		}
	}
}

⌨️ 快捷键说明

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