亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bytebuffer.java

?? Short Message Peer to Peer
?? JAVA
字號:
/*
 * Copyright (c) 1996-2001
 * Logica Mobile Networks Limited
 * All rights reserved.
 *
 * This software is distributed under Logica Open Source License Version 1.0
 * ("Licence Agreement"). You shall use it and distribute only in accordance
 * with the terms of the License Agreement.
 *
 */
package org.smpp.util;

import java.io.UnsupportedEncodingException;

import org.smpp.Data;
import org.smpp.SmppObject;

/**
 * Data buffer for queued writting and reading of binary data.
 * Provides methods for appending several data types to the end of the buffer
 * and removing them from the begenning of the buffer. Used for constructing
 * and parsing binary PDUs.
 *
 * @author Logica Mobile Networks SMPP Open Source Team
 * @version $Revision: 1.5 $
 */
public class ByteBuffer extends SmppObject {

	private byte[] buffer;

	private static final byte SZ_BYTE = 1;
	private static final byte SZ_SHORT = 2;
	private static final byte SZ_INT = 4;
	private static final byte SZ_LONG = 8;

	private static byte[] zero;

	static {
		zero = new byte[1];
		zero[0] = 0;
	}

	public ByteBuffer() {
		buffer = null;
	}

	public ByteBuffer(byte[] buffer) {
		this.buffer = buffer;
	}

	public byte[] getBuffer() {
		return buffer;
	}

	public void setBuffer(byte[] buffer) {
		this.buffer = buffer;
	}

	public int length() {
		if (buffer == null) {
			return 0;
		} else {
			return buffer.length;
		}
	}

	private static int length(byte[] buffer) {
		if (buffer == null) {
			return 0;
		} else {
			return buffer.length;
		}
	}

	public void appendByte(byte data) {
		byte[] byteBuf = new byte[SZ_BYTE];
		byteBuf[0] = data;
		appendBytes0(byteBuf, SZ_BYTE);
	}

	public void appendShort(short data) {
		byte[] shortBuf = new byte[SZ_SHORT];
		shortBuf[1] = (byte) (data & 0xff);
		shortBuf[0] = (byte) ((data >>> 8) & 0xff);
		appendBytes0(shortBuf, SZ_SHORT);
	}

	public void appendInt(int data) {
		byte[] intBuf = new byte[SZ_INT];
		intBuf[3] = (byte) (data & 0xff);
		intBuf[2] = (byte) ((data >>> 8) & 0xff);
		intBuf[1] = (byte) ((data >>> 16) & 0xff);
		intBuf[0] = (byte) ((data >>> 24) & 0xff);
		appendBytes0(intBuf, SZ_INT);
	}

	public void appendCString(String string) {
		try {
			appendString0(string, true, Data.ENC_GSM7BIT);
		} catch (UnsupportedEncodingException e) {
			try {
				appendString0(string, true, Data.ENC_ASCII);
			} catch (UnsupportedEncodingException e2) {
				// this can't happen as we use ASCII encoding
				// whatever is in the buffer it gets interpreted as ascii
			}
		}
	}

	public void appendCString(String string, String encoding) throws UnsupportedEncodingException {
		appendString0(string, true, encoding);
	}

	public void appendString(String string) {
		try {
			appendString(string, Data.ENC_GSM7BIT);
		} catch (UnsupportedEncodingException e) {
			try {
				appendString(string, Data.ENC_ASCII);
			} catch (UnsupportedEncodingException e2) {
				// this can't happen as we use ASCII encoding
				// whatever is in the buffer it gets interpreted as ascii
			}
		}
	}

	public void appendString(String string, String encoding) throws UnsupportedEncodingException {
		appendString0(string, false, encoding);
	}

	public void appendString(String string, int count) {
		try {
			appendString(string, count, Data.ENC_GSM7BIT);
		} catch (UnsupportedEncodingException e) {
			try {
				appendString(string, count, Data.ENC_ASCII);
			} catch (UnsupportedEncodingException e2) {
				// this can't happen as we use ASCII encoding
				// whatever is in the buffer it gets interpreted as ascii
			}
		}
	}

	public void appendString(String string, int count, String encoding) throws UnsupportedEncodingException {
		String subStr = string.substring(0, count);
		appendString0(subStr, false, encoding);
	}

	private void appendString0(String string, boolean isCString, String encoding) throws UnsupportedEncodingException {
		if ((string != null) && (string.length() > 0)) {
			byte[] stringBuf = null;
			if (encoding != null) {
				stringBuf = string.getBytes(encoding);
			} else {
				stringBuf = string.getBytes();
			}
			if ((stringBuf != null) && (stringBuf.length > 0)) {
				appendBytes0(stringBuf, stringBuf.length);
			}
		}
		if (isCString) {
			appendBytes0(zero, 1); // always append terminating zero
		}
	}

	public void appendBuffer(ByteBuffer buf) {
		if (buf != null) {
			try {
				appendBytes(buf, buf.length());
			} catch (NotEnoughDataInByteBufferException e) {
				// can't happen as appendBytes only complains
				// when count>buf.length
			}
		}
	}

	public void appendBytes(ByteBuffer bytes, int count) throws NotEnoughDataInByteBufferException {
		if (count > 0) {
			if (bytes == null) {
				throw new NotEnoughDataInByteBufferException(0, count);
			}
			if (bytes.length() < count) {
				throw new NotEnoughDataInByteBufferException(bytes.length(), count);
			}
			appendBytes0(bytes.getBuffer(), count);
		}
	}

	public void appendBytes(byte[] bytes, int count) {
		if (bytes != null) {
			if (count > bytes.length) {
				count = bytes.length;
			}
			appendBytes0(bytes, count);
		}
	}

	public void appendBytes(byte[] bytes) {
		if (bytes != null) {
			appendBytes0(bytes, bytes.length);
		}
	}

	public byte removeByte() throws NotEnoughDataInByteBufferException {
		byte result = 0;
		byte[] resBuff = removeBytes(SZ_BYTE).getBuffer();
		result = resBuff[0];
		return result;
	}

	public short removeShort() throws NotEnoughDataInByteBufferException {
		short result = 0;
		byte[] resBuff = removeBytes(SZ_SHORT).getBuffer();
		result |= resBuff[0] & 0xff;
		result <<= 8;
		result |= resBuff[1] & 0xff;
		return result;
	}

	public int removeInt() throws NotEnoughDataInByteBufferException {
		int result = readInt();
		removeBytes0(SZ_INT);
		return result;
	}

	public int readInt() throws NotEnoughDataInByteBufferException {
		int result = 0;
		int len = length();
		if (len >= SZ_INT) {
			result |= buffer[0] & 0xff;
			result <<= 8;
			result |= buffer[1] & 0xff;
			result <<= 8;
			result |= buffer[2] & 0xff;
			result <<= 8;
			result |= buffer[3] & 0xff;
			return result;
		} else {
			throw new NotEnoughDataInByteBufferException(len, 4);
		}
	}

	public String removeCString() throws NotEnoughDataInByteBufferException, TerminatingZeroNotFoundException {
		int len = length();
		int zeroPos = 0;
		if (len == 0) {
			throw new NotEnoughDataInByteBufferException(0, 1);
		}
		while ((zeroPos < len) && (buffer[zeroPos] != 0)) {
			zeroPos++;
		}
		if (zeroPos < len) { // found terminating zero
			String result = null;
			if (zeroPos > 0) {
				try {
					result = new String(buffer, 0, zeroPos, Data.ENC_GSM7BIT);
				} catch (UnsupportedEncodingException e) {
					try {
						result = new String(buffer, 0, zeroPos, Data.ENC_ASCII);
					} catch (UnsupportedEncodingException e2) {
						// this can't happen as we use ASCII encoding
						// whatever is in the buffer it gets interpreted as ascii
					}
				}
			} else {
				result = new String("");
			}
			removeBytes0(zeroPos + 1);
			return result;
		} else {
			throw new TerminatingZeroNotFoundException();
		}
	}

	public String removeString(int size, String encoding)
		throws NotEnoughDataInByteBufferException, UnsupportedEncodingException {
		int len = length();
		if (len < size) {
			throw new NotEnoughDataInByteBufferException(len, size);
		}
		UnsupportedEncodingException encodingException = null;
		String result = null;
		if (len > 0) {
			try {
				if (encoding != null) {
					result = new String(buffer, 0, size, encoding);
				} else {
					result = new String(buffer, 0, size);
				}
			} catch (UnsupportedEncodingException e) {
				debug.write("Unsupported encoding exception " + e);
				event.write(e, null);
				encodingException = e;
			}
			removeBytes0(size);
		} else {
			result = new String("");
		}
		if (encodingException != null) {
			throw encodingException;
		}
		return result;
	}

	public ByteBuffer removeBuffer(int count) throws NotEnoughDataInByteBufferException {
		return removeBytes(count);
	}

	public ByteBuffer removeBytes(int count) throws NotEnoughDataInByteBufferException {
		ByteBuffer result = readBytes(count);
		removeBytes0(count);
		return result;
	}

	// just removes bytes from the buffer and doesnt return anything
	public void removeBytes0(int count) throws NotEnoughDataInByteBufferException {
		// paolo@bulksms.com: seeing as how these libs return 32-bit unsigned ints
		// (by using negative values), they should also cater for them in input.
		// However, it's unlikely to be happen often (mostly occurs with garbage
		// input), so I'm not fixing it, but just adding this quickly to stop
		//  ArrayIndexOutOfBoundsExceptions with large values:
		if (count < 0) count = Integer.MAX_VALUE;

		int len = length();
		int lefts = len - count;
		if (lefts > 0) {
			byte[] newBuf = new byte[lefts];
			System.arraycopy(buffer, count, newBuf, 0, lefts);
			setBuffer(newBuf);
		} else {
			setBuffer(null);
		}
	}

	public ByteBuffer readBytes(int count) throws NotEnoughDataInByteBufferException {
		int len = length();
		ByteBuffer result = null;
		if (count > 0) {
			if (len >= count) {
				byte[] resBuf = new byte[count];
				System.arraycopy(buffer, 0, resBuf, 0, count);
				result = new ByteBuffer(resBuf);
				return result;
			} else {
				throw new NotEnoughDataInByteBufferException(len, count);
			}
		} else {
			return result; // just null as wanted count = 0
		}
	}

	// everything must be checked before calling this method
	// and count > 0
	private void appendBytes0(byte[] bytes, int count) {
		int len = length();
		byte[] newBuf = new byte[len + count];
		if (len > 0) {
			System.arraycopy(buffer, 0, newBuf, 0, len);
		}
		System.arraycopy(bytes, 0, newBuf, len, count);
		setBuffer(newBuf);
	}

	public String getHexDump() {
		String dump = "";
		try {
			int dataLen = length();
			byte[] buffer = getBuffer();
			for (int i = 0; i < dataLen; i++) {
				dump += Character.forDigit((buffer[i] >> 4) & 0x0f, 16);
				dump += Character.forDigit(buffer[i] & 0x0f, 16);
			}
		} catch (Throwable t) {
			// catch everything as this is for debug
			dump = "Throwable caught when dumping = " + t;
		}
		return dump;
	}
}
/*
 * $Log: ByteBuffer.java,v $
 * Revision 1.5  2004/09/04 08:07:21  paoloc
 * Minor change to stop ArrayIndexOutOfBoundsExceptions when parsing garbage input
 *
 * Revision 1.4  2004/01/07 21:51:52  sverkera
 * Fallback silently from Gsm Default to Ascii if it's not supported
 *
 * Revision 1.3  2004/01/07 21:37:08  sverkera
 * Removed a debug printout that just adds confusion
 *
 * Revision 1.2  2003/09/30 09:13:02  sverkera
 * Changed to use GSM 7Bit as default
 *
 * Revision 1.1  2003/07/23 00:28:39  sverkera
 * Imported
 *
 * 
 * Old changelog:
 * 13-07-01 ticp@logica.com fixed appendString(String,int) which was appending
 *                          appending one byte less than it had to; it was also
 *                          appending terminationg zero which it hadn't to :-)
 * 13-07-01 ticp@logica.com added getHexDump() function which returns the content
 *                          of the buffer in hex as String
 * 26-09-01 ticp@logica.com fixed getHexDump - hi byte masked with 0x0f to mask-out
 *                          the sign which got extended to the hi byte after shift
 *                          right
 * 27-09-01 ticp@logica.com added method for appending first count bytes
 *                          from byte[]
 * 15-11-01 ticp@logica.com added support for appending strings with explicitly
 *                          stated character encoding
 * 20-11-01 ticp@logica.com fixed bug in appendString0 where if param string
 *                          was null, NullPointerException was thrown
 */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美日韩电影| 日韩福利视频导航| 欧美成人官网二区| 99国产精品国产精品久久| 日韩av一区二区三区四区| 国产精品丝袜在线| 精品国产一区二区国模嫣然| 在线亚洲精品福利网址导航| 国产aⅴ综合色| 精品一区二区三区在线播放 | 欧美日韩国产在线观看| 国产99久久久国产精品免费看| 婷婷夜色潮精品综合在线| ...xxx性欧美| 国产亚洲一区二区三区在线观看| 制服丝袜亚洲网站| 精品视频一区三区九区| 日韩欧美国产电影| 精品视频在线视频| 91在线观看高清| 粉嫩绯色av一区二区在线观看 | 国内精品久久久久影院薰衣草 | 亚洲午夜久久久久中文字幕久| 欧美国产视频在线| 久久青草欧美一区二区三区| 日韩精品专区在线影院观看| 欧美另类一区二区三区| 欧美日韩视频不卡| 欧美日韩免费不卡视频一区二区三区| 成人毛片老司机大片| 国产一区二区三区免费观看| 韩国欧美一区二区| 久久99国产精品久久99| 极品少妇xxxx精品少妇偷拍| 蜜臂av日日欢夜夜爽一区| 日本一区中文字幕| 日产欧产美韩系列久久99| 五月天中文字幕一区二区| 亚洲成人av一区| 日韩制服丝袜av| 免费成人性网站| 精品一区二区三区在线观看国产 | 日韩av电影免费观看高清完整版| 同产精品九九九| 日本欧美一区二区在线观看| 美洲天堂一区二卡三卡四卡视频| 免播放器亚洲一区| 国产一区视频在线看| 粉嫩av一区二区三区粉嫩| av在线不卡免费看| 成人黄色综合网站| 91丝袜美腿高跟国产极品老师| 成人91在线观看| 在线观看免费一区| 91精品国产色综合久久不卡蜜臀| 日韩视频一区二区在线观看| 久久综合狠狠综合| 国产精品大尺度| 亚洲一级二级在线| 另类小说欧美激情| 在线观看91av| 精品日韩一区二区| 中文字幕av一区二区三区高| 亚洲三级电影网站| 日日摸夜夜添夜夜添精品视频| 久久国产生活片100| 成人激情免费视频| 欧美裸体bbwbbwbbw| 精品少妇一区二区三区在线播放| 欧美国产日韩在线观看| 亚洲综合激情网| 国产在线观看一区二区| 91麻豆国产福利精品| 91麻豆精品国产自产在线| 久久久久久久久久美女| 一区在线播放视频| 日韩电影免费在线观看网站| 国产成人在线看| 欧美在线一区二区| 国产欧美日韩另类一区| 亚洲一区国产视频| 国产剧情一区在线| 欧美三区在线观看| 欧美国产激情二区三区| 性欧美大战久久久久久久久| 国产成人av电影在线观看| 欧美性大战久久久久久久| 久久久噜噜噜久噜久久综合| 夜夜精品视频一区二区| 国产乱对白刺激视频不卡| 欧美视频一区在线| 国产欧美一区二区精品性色超碰| 亚洲一卡二卡三卡四卡| 盗摄精品av一区二区三区| 欧美高清你懂得| 自拍av一区二区三区| 激情成人午夜视频| 欧美日韩美女一区二区| 日本一区二区三区在线不卡| 日韩av午夜在线观看| 色婷婷精品久久二区二区蜜臂av | 91福利在线导航| 亚洲国产综合91精品麻豆| 激情av综合网| 欧美一级二级三级乱码| 亚洲狠狠丁香婷婷综合久久久| 国产成人精品一区二区三区网站观看| 欧美精品久久天天躁| 一区二区三区在线视频观看| 国产91清纯白嫩初高中在线观看| 日韩欧美精品在线| 三级不卡在线观看| 欧美视频一区二区三区四区| 亚洲日本在线观看| www.视频一区| 国产清纯美女被跳蛋高潮一区二区久久w | 国产剧情一区在线| 日韩欧美一二三四区| 日韩高清在线观看| 欧美日韩极品在线观看一区| 一区二区三区在线视频免费| 色综合久久综合网| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 欧美日韩国产中文| 一区二区三区日本| 色狠狠一区二区| 亚洲欧美电影院| 色婷婷综合视频在线观看| 国产精品免费人成网站| av电影天堂一区二区在线 | 中文av字幕一区| 国产成人精品综合在线观看 | 午夜一区二区三区视频| 欧美唯美清纯偷拍| 亚洲高清免费一级二级三级| 欧美午夜精品一区| 亚洲成av人在线观看| 91精品国产福利| 日本欧美加勒比视频| 欧美α欧美αv大片| 国产一区视频在线看| 欧美激情在线免费观看| 成人性色生活片| 18涩涩午夜精品.www| 色综合久久99| 亚洲国产欧美另类丝袜| 欧美精品18+| 美国十次了思思久久精品导航| 亚洲精品在线电影| 成人免费毛片aaaaa**| 亚洲色图欧美在线| 欧美伊人精品成人久久综合97 | 欧美喷潮久久久xxxxx| 婷婷六月综合亚洲| 精品剧情在线观看| 成人精品电影在线观看| 亚洲人被黑人高潮完整版| 欧美人狂配大交3d怪物一区| 蜜桃久久av一区| 欧美激情一区不卡| 色偷偷久久人人79超碰人人澡| 亚洲二区在线视频| 欧美mv日韩mv国产网站| 99久久精品免费| 日韩精品欧美精品| 久久久久国产成人精品亚洲午夜| 成人99免费视频| 视频在线观看一区| 国产日韩精品一区| 欧美在线free| 九九精品一区二区| 亚洲色欲色欲www| 91精品国产综合久久精品| 高清视频一区二区| 亚洲国产aⅴ天堂久久| 久久久精品日韩欧美| 欧美在线不卡一区| 国产麻豆一精品一av一免费| 亚洲精品视频一区| 欧美zozo另类异族| 欧美自拍偷拍午夜视频| 国产激情91久久精品导航| 亚洲国产一区视频| 国产亚洲欧美日韩在线一区| 欧美日韩国产成人在线免费| 国产在线精品一区二区不卡了 | 亚洲精品中文字幕在线观看| 欧美一级日韩一级| 91在线视频播放| 国产一区二区精品久久| 午夜精品一区二区三区电影天堂 | 国产欧美日韩中文久久| 在线播放中文一区| 99精品国产91久久久久久 | 欧洲视频一区二区| 国产大片一区二区| 蜜臀av一区二区| 亚洲精品大片www| 中文字幕在线视频一区| 精品国产91亚洲一区二区三区婷婷 |