AppInfo.java

Go to the documentation of this file.
00001 package org.gnu.pilotlink;
00002 
00003 public abstract class AppInfo {
00004     protected byte buffer[];
00005     protected String categories[]=new String[16];
00006     protected boolean isCatRenamed[]=new boolean[16];
00007     protected int catCount=0;
00008     protected int dataOffset=0;
00009     protected int bits;
00010     protected long id[];
00011     protected int lastUniqueID;
00012     
00013     public AppInfo() {
00014         buffer=new byte[65535];
00015     }
00016     
00017     public AppInfo(AppInfo ai) {
00018         setBuffer(ai.getBuffer());
00019     }
00020 
00021     public abstract void setBuffer(byte[] b);
00022     
00023     public void parseCategories(){
00024         bits=buffer[0]*256+buffer[1];
00025         id=new long[4];
00026         catCount=0;
00027         for (int i=0; i<16; i++) {
00028                 if (buffer[2+i*16]!=0) {
00029                         categories[i]=getStringAt(buffer,2+i*16);
00030                                  //=new String(buffer,2+i*16,16);
00031                         
00032                         //System.out.println("Got Category: \""+categories[i]+"\"");
00033                         catCount++;
00034                 } else {
00035                         categories[i]=null;
00036                 }
00037                 if ( (bits&(1<<i))!=0) {
00038                         isCatRenamed[i]=true;
00039                 } else {
00040                         isCatRenamed[i]=false;
00041                 }
00042         }       
00043         dataOffset=2+16*16;
00044         for (int i=0; i<4; i++) {
00045                 id[i]=Record.getLongAt(buffer,dataOffset);
00046                 dataOffset+=4;
00047         }
00048         lastUniqueID=buffer[dataOffset];
00049         dataOffset+=4;
00050         
00051         
00052     }
00053     
00054     public void createDefaultBuffer() {
00055         for (int i=0; i<buffer.length; i++) {
00056                 buffer[i]=0;
00057         }
00058     
00059         bits=0;
00060         for (int i=0; i<16; i++) {
00061                 if (isCatRenamed[i]) {
00062                         bits|=(1<<i);
00063                 }
00064                 if (categories[i]!=null) {
00065                         for (int ch=0;ch<16 && ch<categories[i].length();ch++) {
00066                                 char z=categories[i].charAt(ch);
00067                                 buffer[2+i*16+ch]=(byte)z;
00068                         }
00069                 }                       
00070         }
00071         buffer[0]=(byte) (bits>>256);
00072         buffer[1]=(byte) (bits&256);
00073     }
00074     
00075     
00076     public abstract byte[] getBuffer() ;
00077     public boolean isCatRenamed(int idx) {
00078         return isCatRenamed[idx];
00079     }
00080     public void setCatRenamed(int idx,boolean b) {
00081         isCatRenamed[idx]=b;
00082     }
00083     
00084     public String getCatName(int idx) {
00085         return categories[idx];
00086     }
00087     public void setCatName(int idx,String n){
00088         if (n.length()>16) {
00089                 n=n.substring(0,16);
00090         }
00091         categories[idx]=n;
00092     }
00093     
00094     public static String getStringAt(byte buffer[], int idx) {
00095         String str="";
00096         while (idx<buffer.length && str.length()<16&&buffer[idx]!=0) {
00097                 
00098                 str+=(char)buffer[idx];
00099                 
00100                 idx++;
00101         }
00102         return str;
00103     }
00104     public int getCatCount() {
00105         return catCount;
00106     }
00107     
00108     public String toString() {
00109         String out="Kategories";
00110         for (int i=0; i<16; i++) {
00111                 out+=" "+categories[i];
00112                 if (isCatRenamed(i)) {
00113                         out+="(ren)";
00114                 }
00115         }
00116         return out;
00117     }
00118 }

© 1996-2007 by pilot-link.org. All rights reserved.