SGIPAbstractStruct.java
资源名称:sgip_java.rar [点击查看]
上传用户:leafage163
上传日期:2022-08-08
资源大小:15k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package com.zzxy.shortmessage.SGIP;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- public abstract class SGIPAbstractStruct {
- public static final int STRUCT_MAX_SIZE = 1024 * 4; // 4K
- public Head head = null;
- public static final String charset = "GB2312";
- public final ByteOrder byteOrder =ByteOrder.BIG_ENDIAN;
- public final ByteBuffer getAllBuffer() throws Exception {
- ByteBuffer buffer = ByteBuffer.allocate(this.getHead().getBuffer().capacity()
- + this.getBuffer().capacity());
- buffer.order(byteOrder);
- buffer.put(this.getHead().getBuffer());
- buffer.put(this.getBuffer());
- buffer.flip();
- return buffer;
- }
- public final void setAllBuffer(ByteBuffer buffer) throws Exception {
- buffer.order(byteOrder);
- this.setHead(new Head());
- this.getHead().setBuffer(buffer);
- this.setBuffer(buffer);
- }
- public final void setHead(Head head) {
- this.head = head;
- }
- public final Head getHead() {
- return head;
- }
- public abstract ByteBuffer getBuffer()throws Exception;
- public abstract void setBuffer(ByteBuffer buffer) throws Exception;
- }