JML

net.sf.jqql.obsolete
Class FileDataPacket

java.lang.Object
  extended by net.sf.jqql.obsolete.FilePacket
      extended by net.sf.jqql.obsolete.FileDataPacket

public class FileDataPacket
extends FilePacket

 file operation info packet, this packet take some basic info of file, format is:
    1. head
    2. unknown byte, 0x00
    3. 2 byte operation type, format behind is:
         1. when operate type is 0x1, maybe mean to begin to send basic info of file, format is:
            i. 3 unknown byte, all 0
        2. when operate type is 0x2, maybe mean to begin to send file data, format is the same
            as 0x1
        3. when operate type is 0x3, maybe mean that transfering ends, the same format as when 0x1
        4. when operate type is 0x7, indicate related operation of file, according to sub operate type,
        the content is different, format is:
        a. when sub operate type is 0x1, it's the transfer of file basic info, format is:
            i. two byte, all 0, usage unknown
            ii. sub operate byte 0x1
            iii. file length, 4 byte
            iv. file data fragment count, one time send 1000byte, so this field is couted base on iii, 4 byte
            v. max length of fragment, 4 byte, often 1000byte a fragment, only the last fragment is not with
                the max length.
            vi. 16 byte md5, for small file, this is the whole file's md5. For file larger than 10002432 byte, the 
                md5 is the leading 10002435 byte. Amazing, why choose this no-rule digit, make me feel sick.
            vii. file name's MD5, 16 byte
            ix. 8 unknown byte, all 0
            x. file name

 文件操作信息包,这个包里面携带了文件的一些基本信息,格式为
 1. 头部
 2. 未知字节,0x00
 3. 2字节操作类型,后续格式为
    1. 操作类型为0x1时,可能是表示开始传送文件基本信息,格式为
       i.  三个未知字节,全0
    2. 操作类型为0x2时,可能是表示开始传送文件的数据,格式和0x1时相同
    3. 操作类型为0x3时,可能时表示传送结束,格式和0x1时相同
    4. 如果操作类型为0x7,表示文件相关操作,根据子操作类型内容有所不同,格式为
       a. 当子操作类型为0x1时,表示文件基本信息传输,格式为
                i.   两个字节,为全0,作用未知
              ii.  子操作类型字节0x1
           iii. 文件长度,四字节
           iv.  文件数据分片数,一次传送1000字节,所以这个域是根据iii计算出来的,4字节
           v.   每个分片的最大长度,4字节,一般都是1000字节一个分片,只有最后一个不是最大字节数
           vi.  16个字节的md5,对于较小的文件,这个就是全部文件的md5,对于超过10002432字节的
               文件,这个MD5是前10002432字节的MD5。太变态了,为什么选这么一个没规律的数字。找
               的我头都晕了。
          vii. 文件名的MD5,16字节
           viii. 文件名字节长度,2字节
           ix.  八个未知字节,全0
           x.   文件名

    b. If the sub operate type is 0x2, it means file transfer, format is:
        i. message packet sequence 
        ii. sub operate type byte 0x2
        iii. fragment suqence, 4 byte
        iv.  absulute offset of current fragment in the file, 4 byte
        v. data byte count contained by current, 2 byte
        vi. real data
    c. If the sub operate type is 0x3, it means the transfer ends, format is:
        i. the biggest fragment sequence add 1. for example, if the file is divided into two
            fragment to send, here is 3, 2 byte
        ii. sub operate type 0x3
 
       b. 如果子操作类型为0x2,表示文件数据传输,格式为
           i.   消息包的顺序号
           ii.  子操作类型字节0x2
           iii. 分片序号,4字节
           iv.  当前分片在文件中的绝对偏移, 4字节
           v.   当前包含的数据字节数,2字节
           vi.  实际的数据
       c. 如果子操作类型为0x3,表示文件传送结束,格式为
           i.   最大分片序号加1,例如如果文件分成两个分片发送,那么这里就是3,2字节
           ii.  子操作类型0x3

    5. when operate type is 0x8, it's 0x7 operation 's reply packet. According to different sub operate
    there are different reply packet. format is:
        a. If sub operate type is 0x1, it means the file basic info Ack is received, format is:
        i. two unknown byte, 0x0000
        ii. sub operate type field, 0x1, 1 byte
        iii. unknown 4 byte, all 0
        b. If the sub operate is 0x2, it mwan that the file fragment is received, format is :
        i. packet sequence
        ii. sub operate type field, 0x2, 1 byte
        ii. fragment sequence, 4 byte
        c. If the sub operate type is 0x3, it mean the ending info is received, format is:
        i. the biggest fragment sequence add 1 ,  2 byte
        ii. sub operate type field, 0x3, 1 byte

    5. 操作类型为0x8时,为0x7操作的回复包,根据子操作类型不同而不同,格式为
            a. 如果子操作类型为0x1,表示确认文件基本信息已经收到,格式为
             i.   未知两个字节,0x0000
             ii.  子操作类型字段,0x1,1字节
             iii. 未知的四字节,全0
         b. 如果子操作类型为0x2,表示已经收到了文件分片,格式为
             i.   包顺序号
             ii.  子操作类型字段,0x2,1字节
             iii. 分片序号,4字节
         c. 如果子操作类型是0x3,表示已经收到了结束信息,格式为
             i.   最大的分片序号再加1,2字节
             ii.  子操作类型字段,0x3,1字节
 
 note: this kind of packet need not to encode.
 注意:这种包都不是加密的
 

Author:
luma

Field Summary
 
Fields inherited from class net.sf.jqql.obsolete.FilePacket
crypter, key, log, random, receiver, sender, source, tag, watcher
 
Constructor Summary
FileDataPacket(FileWatcher watcher)
          construct a send packet 构造一个发送包
 
Method Summary
 boolean equals(Object obj)
           
protected  void fill(ByteBuffer out)
           initialize packet content, subclass should overide this method, and first use this method in super class × content of input ByteBuffer will be clear, after complete, buffer position equal to packet length 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法 输入ByteBuffer原来的内容将被清空,完成后,bufferçš„position 等于包长
protected  void fill(ByteBuffer out, int from)
           initialize packet content, subclass should overide this method, and first use this method in super class content of input ByteBuffer won't be clear, new content start fill from from position, after complete, buffer position = packet length + from 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法 输入ByteBuffer的原来内容不被清空,新的内容从from位置开始 填充,完成后,bufferçš„position等于包长加上from
 char getCommand()
           
 byte[] getFileMD5()
           
 String getFileName()
           
 byte[] getFileNameMD5()
           
 int getFileSize()
           
 byte[] getFragmentData()
           
 int getFragmentIndex()
           
 int getFragmentLength()
           
 int getFragmentMaxSize()
           
 int getFragmentOffset()
           
 int getFragments()
           
 char getHeartBeatSequence()
           
 byte getInfoType()
           
 int getPacketIndex()
           
 int hashCode()
           
protected  void initFixedFields()
          init some fixed field toward fixed type packet 初始化一些对于固定类型的包来说固定值的字段
protected  void parse(ByteBuffer in)
          parse packet header, subclass should overide this method, and first use this method in super class parse start from current position of in, after parse complete, position of in will be after this packet 解析包头,子类应该覆盖该方法,并首先调用父类的这个方法 解析从in的当前位置开始,解析完毕后inçš„position将位于 这个包之后
 void setCommand(char command)
           
 void setFileMD5(byte[] firstMD5)
           
 void setFileName(String fileName)
           
 void setFileNameMD5(byte[] secondMD5)
           
 void setFileSize(int fileSize)
           
 void setFragmentData(byte[] framgentData)
           
 void setFragmentIndex(int fragmentIndex)
           
 void setFragmentLength(int fragmentSize)
           
 void setFragmentMaxSize(int fragmentMaxSize)
           
 void setFragmentOffset(int fragmentOffset)
           
 void setHeartBeatSequence(char heartBeatSequence)
           
 void setInfoType(byte infoType)
           
 void setPacketIndex(int packetIndex)
           
 
Methods inherited from class net.sf.jqql.obsolete.FilePacket
decryptQQ, encryptQQ, generateKey, getKey, getReceiver, getSender, getSource, getTag, refreshKey, setReceiver, setSender, setSource, setTag
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDataPacket

public FileDataPacket(FileWatcher watcher)
construct a send packet 构造一个发送包

Parameters:
watcher - FileWatcher object
watcher - FileWatcher对象
Method Detail

fill

protected void fill(ByteBuffer out)
Description copied from class: FilePacket
 initialize packet content, subclass should overide this method, and first use this method in super class
     × content of input ByteBuffer will be clear, after complete, buffer position equal to packet length
 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法
 输入ByteBuffer原来的内容将被清空,完成后,buffer的position
 等于包长
 

Overrides:
fill in class FilePacket
Parameters:
out - ByteBuffer对象,做为输出缓冲区 // ByteBuffer object, use to output buffer

fill

protected void fill(ByteBuffer out,
                    int from)
Description copied from class: FilePacket
 initialize packet content, subclass should overide this method, and first use this method in super class
 content of input ByteBuffer won't be clear, new content start fill from from position, after complete,
 buffer position = packet length + from
 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法
 输入ByteBuffer的原来内容不被清空,新的内容从from位置开始
 填充,完成后,buffer的position等于包长加上from
 

Overrides:
fill in class FilePacket
Parameters:
out - ByteBuffer对象,做为输出缓冲区 // ByteBuffer object, use to output buffer
from - 开始填充的位置 //start fill position

parse

protected void parse(ByteBuffer in)
              throws PacketParseException
Description copied from class: FilePacket
parse packet header, subclass should overide this method, and first use this method in super class parse start from current position of in, after parse complete, position of in will be after this packet 解析包头,子类应该覆盖该方法,并首先调用父类的这个方法 解析从in的当前位置开始,解析完毕后in的position将位于 这个包之后

Overrides:
parse in class FilePacket
Parameters:
in - ByteBuffer对象,做为输入缓冲区 // ByteBuffer object, as input buffer
Throws:
PacketParseException

getFileSize

public int getFileSize()
Returns:
Returns the fileSize.

setFileSize

public void setFileSize(int fileSize)
Parameters:
fileSize - The fileSize to set.

getFileName

public String getFileName()
Returns:
Returns the fileName.

setFileName

public void setFileName(String fileName)
Parameters:
fileName - The fileName to set.

getPacketIndex

public int getPacketIndex()
Returns:
Returns the fragment.

setPacketIndex

public void setPacketIndex(int packetIndex)
Parameters:
packetIndex - The fragment to set.

getFragmentOffset

public int getFragmentOffset()
Returns:
Returns the fragmentOffset.

setFragmentOffset

public void setFragmentOffset(int fragmentOffset)
Parameters:
fragmentOffset - The fragmentOffset to set.

getFragmentLength

public int getFragmentLength()
Returns:
Returns the fragmentSize.

setFragmentLength

public void setFragmentLength(int fragmentSize)
Parameters:
fragmentSize - The fragmentSize to set.

getFragmentData

public byte[] getFragmentData()
Returns:
Returns the framgentData.

setFragmentData

public void setFragmentData(byte[] framgentData)
Parameters:
framgentData - The framgentData to set.

getInfoType

public byte getInfoType()
Returns:
Returns the infoType.

setInfoType

public void setInfoType(byte infoType)
Parameters:
infoType - The infoType to set.

getFragments

public int getFragments()
Returns:
Returns the fragments.

getFragmentIndex

public int getFragmentIndex()
Returns:
Returns the fragmentReceived.

setFragmentIndex

public void setFragmentIndex(int fragmentIndex)
Parameters:
fragmentIndex - The fragmentReceived to set.

getHeartBeatSequence

public char getHeartBeatSequence()
Returns:
Returns the heartBeatSequence.

setHeartBeatSequence

public void setHeartBeatSequence(char heartBeatSequence)
Parameters:
heartBeatSequence - The heartBeatSequence to set.

getFileMD5

public byte[] getFileMD5()
Returns:
Returns the firstMD5.

setFileMD5

public void setFileMD5(byte[] firstMD5)
Parameters:
firstMD5 - The firstMD5 to set.

getFragmentMaxSize

public int getFragmentMaxSize()
Returns:
Returns the fragmentMaxSize.

setFragmentMaxSize

public void setFragmentMaxSize(int fragmentMaxSize)
Parameters:
fragmentMaxSize - The fragmentMaxSize to set.

getFileNameMD5

public byte[] getFileNameMD5()
Returns:
Returns the secondMD5.

setFileNameMD5

public void setFileNameMD5(byte[] secondMD5)
Parameters:
secondMD5 - The secondMD5 to set.

initFixedFields

protected void initFixedFields()
Description copied from class: FilePacket
init some fixed field toward fixed type packet 初始化一些对于固定类型的包来说固定值的字段

Specified by:
initFixedFields in class FilePacket

getCommand

public char getCommand()
Returns:
Returns the command.

setCommand

public void setCommand(char command)
Parameters:
command - The command to set.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

JML