1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
package org.gnu.pilotlink;
public abstract class AppInfo {
protected byte buffer[];
protected String categories[]=new String[16];
protected boolean isCatRenamed[]=new boolean[16];
protected int catCount=0;
protected int dataOffset=0;
protected int bits;
protected long id[];
protected int lastUniqueID;
public AppInfo() {
buffer=new byte[65535];
}
public AppInfo(AppInfo ai) {
setBuffer(ai.getBuffer());
}
public abstract void setBuffer(byte[] b);
public void parseCategories(){
bits=buffer[0]*256+buffer[1];
id=new long[4];
catCount=0;
for (int i=0; i<16; i++) {
if (buffer[2+i*16]!=0) {
categories[i]=getStringAt(buffer,2+i*16);
//=new String(buffer,2+i*16,16);
//System.out.println("Got Category: \""+categories[i]+"\"");
catCount++;
} else {
categories[i]=null;
}
if ( (bits&(1<<i))!=0) {
isCatRenamed[i]=true;
} else {
isCatRenamed[i]=false;
}
}
dataOffset=2+16*16;
for (int i=0; i<4; i++) {
id[i]=Record.getLongAt(buffer,dataOffset);
dataOffset+=4;
}
lastUniqueID=buffer[dataOffset];
dataOffset+=4;
}
public void createDefaultBuffer() {
for (int i=0; i<buffer.length; i++) {
buffer[i]=0;
}
bits=0;
for (int i=0; i<16; i++) {
if (isCatRenamed[i]) {
bits|=(1<<i);
}
if (categories[i]!=null) {
for (int ch=0;ch<16 && ch<categories[i].length();ch++) {
char z=categories[i].charAt(ch);
buffer[2+i*16+ch]=(byte)z;
}
}
}
buffer[0]=(byte) (bits>>256);
buffer[1]=(byte) (bits&256);
}
public abstract byte[] getBuffer() ;
public boolean isCatRenamed(int idx) {
return isCatRenamed[idx];
}
public void setCatRenamed(int idx,boolean b) {
isCatRenamed[idx]=b;
}
public String getCatName(int idx) {
return categories[idx];
}
public void setCatName(int idx,String n){
if (n.length()>16) {
n=n.substring(0,16);
}
categories[idx]=n;
}
public static String getStringAt(byte buffer[], int idx) {
String str="";
while (idx<buffer.length && str.length()<16&&buffer[idx]!=0) {
str+=(char)buffer[idx];
idx++;
}
return str;
}
public int getCatCount() {
return catCount;
}
public String toString() {
String out="Kategories";
for (int i=0; i<16; i++) {
out+=" "+categories[i];
if (isCatRenamed(i)) {
out+="(ren)";
}
}
return out;
}
}
|