當前位置: 首頁>>代碼示例>>Java>>正文


Java PacketParseException類代碼示例

本文整理匯總了Java中org.opendmtp.server.base.PacketParseException的典型用法代碼示例。如果您正苦於以下問題:Java PacketParseException類的具體用法?Java PacketParseException怎麽用?Java PacketParseException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PacketParseException類屬於org.opendmtp.server.base包,在下文中一共展示了PacketParseException類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractPackets

import org.opendmtp.server.base.PacketParseException; //導入依賴的package包/類
public static Packet[] extractPackets(PendingPacket pp[])
    throws PacketParseException
{
    if (ListTools.isEmpty(pp)) {
        Print.logWarn("No PendingPacket list specified");
        return null;
    } else
    if (pp.length == 1) {
        return pp[0].getPackets();
    } else {
        java.util.List<Packet> v = new Vector<Packet>();
        for (int i = 0; i < pp.length; i++) {
            Packet p[] = pp[i].getPackets();
            ListTools.toList(p, v);
        }
        return v.toArray(new Packet[v.size()]);
    }
}
 
開發者ID:Jebasuthan,項目名稱:vehiclegps,代碼行數:19,代碼來源:PendingPacket.java

示例2: SetPropertyPacket

import org.opendmtp.server.base.PacketParseException; //導入依賴的package包/類
public SetPropertyPacket(int code, String dataStr) throws PacketParseException {
    this.propCode = code;
    Object propArgs[] = PropCodes.parsePropertyValue(code, dataStr);
    if (ListTools.isEmpty(propArgs)) {
        Print.logError("Invalid property value(s) specified: " + dataStr);
        throw new PacketParseException(ServerErrors.NAK_PACKET_PAYLOAD);
    }
    this.propData = PropCodes.encodePropertyData(code, propArgs);
    if (ListTools.isEmpty(this.propData)) {
        Print.logError("Unable to encode property data: " + dataStr);
        throw new PacketParseException(ServerErrors.NAK_PACKET_PAYLOAD);
    }
}
 
開發者ID:Jebasuthan,項目名稱:vehiclegps,代碼行數:14,代碼來源:PendingPacket.java

示例3: createSetPropertyPacket

import org.opendmtp.server.base.PacketParseException; //導入依賴的package包/類
public static SetPropertyPacket createSetPropertyPacket(int propCode, String propDataStr)
{
    try {
        return new SetPropertyPacket(propCode, propDataStr);
    } catch (PacketParseException ppe) {
        return null;
    }
}
 
開發者ID:Jebasuthan,項目名稱:vehiclegps,代碼行數:9,代碼來源:PendingPacket.java

示例4: getPackets

import org.opendmtp.server.base.PacketParseException; //導入依賴的package包/類
public Packet[] getPackets()
    throws PacketParseException
{
    
    /* get bytes representing packets */
    byte b[] = this.getPacketBytes();
    if ((b == null) || (b.length == 0)) {
        Print.logWarn("No packet bytes ...");
        return null;
    }
    
    /* parse packets */
    int ofs = 0;
    java.util.List<Packet> pkts = new Vector<Packet>();
    while (ofs < b.length) {
        int len = Packet.getPacketLength(b, ofs);
        if (len > 0) {
            try {
                byte p[] = new byte[len];
                System.arraycopy(b, ofs, p, 0, len);
                Packet pkt = new Packet(p);
                pkts.add(pkt);
                ofs += len;
            } catch (PacketParseException ppe) {
                // an error occurred while parsing
                // (the data does not represent a valid packet)
                Print.logException("Invalid PendingPacket found!", ppe);
                throw ppe;
            }
        } else {
            Print.logInfo("Premature end of packet bytes: ofs=" + ofs);
            throw new PacketParseException(ServerErrors.NAK_PACKET_LENGTH);
        }
    }
    
    /* return parsed packets */
    int pktCnt = pkts.size();
    if (pktCnt <= 0) {
        Print.logWarn("No packet data found in this pending packet! ...");
        return null;
    } else {
        return pkts.toArray(new Packet[pktCnt]);
    }
    
}
 
開發者ID:Jebasuthan,項目名稱:vehiclegps,代碼行數:46,代碼來源:PendingPacket.java

示例5: insertSetPropertyPacket

import org.opendmtp.server.base.PacketParseException; //導入依賴的package包/類
public static boolean insertSetPropertyPacket(Device device, int propCode, byte propData[], int propDataLen)
    throws DBException
{
    
    /* valid device? */
    if (device == null) {
        Print.logError("Device is null");
        return false;
    }
    String acctId = device.getAccountID();
    String devId  = device.getDeviceID();
    if (acctId.equals("") || devId.equals("")) {
        Print.logError("Account/Device is empty/null");
        return false;
    }

    // Check for, and remove, any existing SetProperty PendingPacket for the specified Property Code
    PendingPacket ppa[] = PendingPacket.getPendingPackets(acctId, devId, -1L);
    if (!ListTools.isEmpty(ppa)) {
        // we do have some existing Pending Packets
        for (int i = 0; i < ppa.length; i++) {
            try {
                Packet pkt[] = PendingPacket.extractPackets(new PendingPacket[] { ppa[i] });
                if (!ListTools.isEmpty(pkt)) {
                    for (int p = 0; p < pkt.length; p++) {
                        if (pkt[p].isBasicPacketHeader() && (pkt[p].getPacketType() == Packet.PKT_SERVER_SET_PROPERTY)) {
                            // we found a SetProperty packet
                            int pktPropCode = (int)pkt[p].getPayload(true).readULong(2,0L);
                            if (pktPropCode == propCode) {
                                // we've found an existing SetProperty with the same code
                                if (pkt.length == 1) {
                                    // only one packet in this PendingPacket, delete this PendingPacket
                                    try {
                                        Print.logInfo("Deleting existing SetProperty for Code: 0x" + StringTools.toHexString(propCode,16));
                                        PendingPacket.Key key = (PendingPacket.Key)ppa[i].getRecordKey();
                                        key.delete(true); // will also delete dependencies (which there are none)
                                    } catch (DBException dbe) {
                                        Print.logException("Unable to delete existing PendingPacket", dbe);
                                        return false;
                                    }
                                } else {
                                    // more than one packet found
                                    Print.logError("A SetProperty for this code already exists!");
                                    return false;
                                }
                            }
                        }
                    }
                } else {
                    // Odd, we found a PendingPacket that contains no Packets (not likely to occur)
                    Print.logWarn("PendingPacket found which does not contain any Packets: " + ppa[i]);
                }
            } catch (PacketParseException ppe) {
                long qt = ppa[i].getQueueTime();
                int seq = ppa[i].getSequence();
                Print.logError("Error parsing packets: queueTime="+qt+ ", sequence="+seq);
            }
         }
    }

    // Queue packet
    PendingPacket pp = new PendingPacket(_CreatePendingPacketKey(acctId,devId));
    Packet propsPkt = Packet.createServerSetPropertyPacket(propCode, propData, propDataLen);
    Print.logInfo("["+acctId+"/"+devId+"] Inserting " + propsPkt);
    pp.setPackets(new Packet[] { propsPkt });
    pp.save();
            
    /* success */
    return true;

}
 
開發者ID:Jebasuthan,項目名稱:vehiclegps,代碼行數:72,代碼來源:PendingPacket.java

示例6: getPendingPackets

import org.opendmtp.server.base.PacketParseException; //導入依賴的package包/類
public PacketList getPendingPackets(boolean allowAutoDelete)
{
    long limit = 1L; // only 1 pending record at a time
    try {
        String acctId = this.getAccountName();
        String devId  = this.getDeviceName();
        PendingPacket pp[] = PendingPacket.getPendingPackets(acctId, devId, limit);
        if ((pp != null) && (pp.length > 0)) {
            try {
                
                /* autodelete/predelete PendingPacket? */
                if (allowAutoDelete) {
                    for (int i = 0; i < pp.length; i++) {
                        if (pp[i].isAutoDelete()) {
                            // pre-delete this PendingPacket now
                        }
                    }
                }
                
                /* extract packets contained in all specified PendingPacket records */
                Packet p[] = PendingPacket.extractPackets(pp);
                if ((p != null) && (p.length > 0)) {
                    // mark PendingPacket record
                    long lastQueueTime = pp[pp.length - 1].getQueueTime();
                    PacketList plist = new PacketList(acctId, devId, p, lastQueueTime);
                    // return what packets we've retrieved
                    return plist;
                } else {
                    return null;
                }
                
            } catch (PacketParseException ppe) {
                
                //PendingPacket.deletePendingPackets(acctId, devId, -1L);
                Print.logException("Unable to parse pending packets", ppe);
                return null;
                
            }
        } else {
            
            // no pending packets
            return null;
            
        }
    } catch (DBException dbe) {
        
        Print.logError("PendingPacket retrieval: " + dbe);
        return null;
        
    }
}
 
開發者ID:Jebasuthan,項目名稱:vehiclegps,代碼行數:52,代碼來源:DeviceDBImpl.java


注:本文中的org.opendmtp.server.base.PacketParseException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。