- 最后登录
- 2023-8-16
- 在线时间
- 1686 小时
- 威望
- 2135
- 金钱
- 50532
- 注册时间
- 2011-10-12
- 阅读权限
- 200
- 帖子
- 5207
- 精华
- 39
- 积分
- 2135
- UID
- 2
|
3#
发表于 2012-1-12 19:56:34
jdbc Packet 包的描述
http://www.oracledatabase12g.com ... ss-description.html- package oracle.net.ns;
- import java.io.*;
- import oracle.net.nl.RepConversion;
- // Referenced classes of package oracle.net.ns:
- // NetException, NetInputStream, SQLnetDef, SessionAtts
- public class Packet
- implements SQLnetDef
- {
- public Packet(Packet packet)
- {
- this(packet.sAtts);
- length = packet.length;
- type = packet.type;
- flags = packet.flags;
- dataLen = packet.dataLen;
- dataOff = packet.dataOff;
- buffer = packet.buffer;
- }
- public Packet(SessionAtts sessionatts)
- {
- header = new byte[8];
- sAtts = sessionatts;
- sdu = sessionatts.getSDU();
- tdu = sessionatts.getTDU();
- }
- public Packet(SessionAtts sessionatts, int i)
- {
- this(sessionatts);
- createBuffer(i);
- }
- public Packet(SessionAtts sessionatts, int i, int j, int k)
- {
- this(sessionatts);
- createBuffer(i, j, k);
- }
- protected void createBuffer(int i)
- {
- buffer = new byte[i];
- buffer[0] = (byte)(i / 256);
- buffer[1] = (byte)(i % 256);
- }
- protected void createBuffer(int i, int j, int k)
- {
- buffer = new byte[i];
- buffer[0] = (byte)(i / 256);
- buffer[1] = (byte)(i % 256);
- buffer[5] = (byte)k;
- buffer[4] = (byte)j;
- }
- protected void dump(byte abyte0[], int i, int j)
- {
- int k = 0;
- System.out.println("Packet dump");
- System.out.println("buffer.length=" + abyte0.length);
- System.out.println("offset =" + i);
- System.out.println("len =" + j);
- for(int l = i; l < j; l += 8 )
- {
- System.out.print("|");
- for(int i1 = 0; i1 < 8 && k < j - 1; i1++)
- {
- k = l + i1;
- RepConversion.printInHex(abyte0[k]);
- System.out.print(" ");
- }
- System.out.println("|");
- }
- System.out.println("finish dump");
- }
- protected void extractData()
- throws IOException, NetException
- {
- if(dataLen <= 0)
- data = new String();
- else
- if(length > dataOff)
- {
- data = new String(buffer, 0, dataOff, dataLen);
- } else
- {
- byte abyte0[] = new byte[dataLen];
- if(sAtts.nsInputStream.read(abyte0) < 0)
- throw new NetException(0);
- data = new String(abyte0, 0);
- }
- }
- protected String getData()
- {
- return data;
- }
- protected void receive()
- throws IOException, NetException
- {
- int i;
- for(i = 0; i < header.length;)
- try
- {
- if((i += sAtts.ntInputStream.read(header, i, header.length - i)) <= 0)
- throw new NetException(0);
- }
- catch(InterruptedIOException _ex)
- {
- throw new NetException(504);
- }
- length = header[0] & 0xff;
- length <<= 8;
- length |= header[1] & 0xff;
- type = header[4];
- flags = header[5];
- if(type > 19)
- throw new NetException(204);
- if(length > 32767 || length > sdu)
- throw new NetException(203);
- if(length < 8 )
- throw new NetException(207);
- buffer[5] = (byte)flags;
- buffer[4] = (byte)type;
- while(i < length)
- try
- {
- if((i += sAtts.ntInputStream.read(buffer, i, length - i)) <= 0)
- throw new NetException(0);
- }
- catch(InterruptedIOException _ex) { }
- }
- protected void send()
- throws IOException
- {
- synchronized(sAtts.ntOutputStream)
- {
- sAtts.ntOutputStream.write(buffer, 0, buffer.length);
- }
- }
- private int buffer2send;
- protected int sdu;
- protected int tdu;
- protected int length;
- public int type;
- protected int flags;
- protected int dataLen;
- protected int dataOff;
- protected String data;
- protected byte buffer[];
- protected byte header[];
- public SessionAtts sAtts;
- }
复制代码 |
|