1 17 package org.alfresco.filesys.smb.server; 18 19 import java.io.PrintStream ; 20 21 import org.alfresco.filesys.util.DataPacker; 22 23 26 class CoreResumeKey 27 { 28 30 private static final int RESBITS = 0; 31 private static final int FILENAME = 1; 32 private static final int RESSERVER = 12; 33 private static final int RESCONSUMER = 17; 34 35 private static final int FILENAMELEN = 11; 36 private static final int RESSRVLEN = 5; 37 private static final int RESCONSUMLEN = 4; 38 39 public static final int LENGTH = 21; 40 41 48 public final static void DumpKey(PrintStream out, byte[] buf, int pos) 49 { 50 51 53 out.print("[" + getReservedByte(buf, pos) + ", "); 54 out.print(getFileName(buf, pos, false) + "]"); 55 } 56 57 62 public static final byte[] getConsumerArea(byte[] buf, int pos) 63 { 64 byte[] conArea = new byte[RESCONSUMLEN]; 65 for (int i = 0; i < RESCONSUMLEN; i++) 66 conArea[i] = buf[pos + RESCONSUMER + i]; 67 return conArea; 68 } 69 70 75 public static final String getFileName(byte[] buf, int pos, boolean dot) 76 { 77 78 80 if (dot) 81 { 82 83 85 StringBuffer name = new StringBuffer (); 86 name.append(new String (buf, pos + FILENAMELEN, 8).trim()); 87 name.append("."); 88 name.append(new String (buf, pos + FILENAMELEN + 8, 3).trim()); 89 90 return name.toString(); 91 } 92 93 95 return new String (buf, pos + FILENAME, FILENAMELEN).trim(); 96 } 97 98 103 public static final byte getReservedByte(byte[] buf, int pos) 104 { 105 return buf[pos]; 106 } 107 108 115 public final static void getResumeKey(byte[] buf, int pos, byte[] key) 116 { 117 118 120 System.arraycopy(buf, pos, key, 0, LENGTH); 121 } 122 123 128 public static final int getServerArea(byte[] buf, int pos) 129 { 130 return DataPacker.getIntelInt(buf, pos + RESSERVER + 1); 131 } 132 133 141 public final static void putResumeKey(byte[] buf, int pos, String fileName, int ctxId) 142 { 143 144 146 buf[pos + RESBITS] = 0x16; 147 148 150 setFileName(buf, pos, fileName); 151 152 154 setServerArea(buf, pos, ctxId); 155 } 157 158 163 public static final void setConsumerArea(byte[] buf, int pos, byte[] conArea) 164 { 165 for (int i = 0; i < RESCONSUMLEN; i++) 166 buf[pos + RESCONSUMER + i] = conArea[i]; 167 } 168 169 174 public static final void setFileName(byte[] buf, int pos, String name) 175 { 176 177 179 StringBuffer str = new StringBuffer (); 180 int dot = name.indexOf("."); 181 if (dot != -1) 182 { 183 str.append(name.substring(0, dot)); 184 while (str.length() < 8) 185 str.append(" "); 186 str.append(name.substring(dot + 1, name.length())); 187 } 188 else 189 str.append(name); 190 191 193 while (str.length() < FILENAMELEN) 194 str.append(" "); 195 196 198 DataPacker.putString(str.toString(), buf, pos + FILENAME, false); 199 } 200 201 206 public static final void setReservedByte(byte[] buf, int pos, byte val) 207 { 208 buf[pos] = val; 209 } 210 211 216 public static final void setServerArea(byte[] buf, int pos, int srvVal) 217 { 218 buf[pos + RESSERVER] = 1; 219 DataPacker.putIntelInt(srvVal, buf, pos + RESSERVER + 1); 220 } 221 } | Popular Tags |