KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > FindInfoPacker


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.server;
18
19 import org.alfresco.filesys.server.filesys.FileInfo;
20 import org.alfresco.filesys.server.filesys.UnsupportedInfoLevelException;
21 import org.alfresco.filesys.smb.NTTime;
22 import org.alfresco.filesys.smb.SMBDate;
23 import org.alfresco.filesys.util.DataBuffer;
24
25 /**
26  * Find Information Packer Class
27  * <p>
28  * Pack file information for a find first/find next information level.
29  */

30 class FindInfoPacker
31 {
32
33     // Enable 8.3 name generation (required for Mac OS9)
34

35     private static final boolean Enable8Dot3Names = false;
36
37     // Enable packing of file id
38

39     private static final boolean EnableFileIdPacking = false;
40
41     // File information levels
42

43     public static final int InfoStandard = 1;
44     public static final int InfoQueryEASize = 2;
45     public static final int InfoQueryEAFromList = 3;
46     public static final int InfoDirectory = 0x101;
47     public static final int InfoFullDirectory = 0x102;
48     public static final int InfoNames = 0x103;
49     public static final int InfoDirectoryBoth = 0x104;
50     public static final int InfoMacHfsInfo = 0x302;
51
52     // File information fixed lengths, includes nulls on strings.
53

54     public static final int InfoStandardLen = 24;
55     public static final int InfoQueryEASizeLen = 28;
56     public static final int InfoDirectoryLen = 64;
57     public static final int InfoFullDirectoryLen = 68;
58     public static final int InfoNamesLen = 12;
59     public static final int InfoDirectoryBothLen = 94;
60     public static final int InfoMacHfsLen = 120;
61
62     /**
63      * Pack a file information object into the specified buffer, using information level 1 format.
64      *
65      * @param info File information to be packed.
66      * @param buf Data buffer to pack the file information into
67      * @param infoLevel File information level.
68      * @param uni Pack Unicode strings if true, else pack ASCII strings
69      * @return Length of data packed
70      */

71     public final static int packInfo(FileInfo info, DataBuffer buf, int infoLevel, boolean uni)
72             throws UnsupportedInfoLevelException
73     {
74
75         // Determine the information level
76

77         int curPos = buf.getPosition();
78
79         switch (infoLevel)
80         {
81
82         // Standard information
83

84         case InfoStandard:
85             packInfoStandard(info, buf, false, uni);
86             break;
87
88         // Standard information + EA list size
89

90         case InfoQueryEASize:
91             packInfoStandard(info, buf, true, uni);
92             break;
93
94         // File name information
95

96         case InfoNames:
97             packInfoFileName(info, buf, uni);
98             break;
99
100         // File/directory information
101

102         case InfoDirectory:
103             packInfoDirectory(info, buf, uni);
104             break;
105
106         // Full file/directory information
107

108         case InfoFullDirectory:
109             packInfoDirectoryFull(info, buf, uni);
110             break;
111
112         // Full file/directory information with short name
113

114         case InfoDirectoryBoth:
115             packInfoDirectoryBoth(info, buf, uni);
116             break;
117
118         // Pack Macintosh format file information
119

120         case InfoMacHfsInfo:
121             packInfoMacHfs(info, buf, uni);
122             break;
123         }
124
125         // Check if we packed any data
126

127         if (curPos == buf.getPosition())
128             throw new UnsupportedInfoLevelException();
129
130         // Return the length of the packed data
131

132         return buf.getPosition() - curPos;
133     }
134
135     /**
136      * Calculate the file name offset for the specified information level.
137      *
138      * @param infoLev int
139      * @param offset int
140      * @return int
141      */

142     public final static int calcFileNameOffset(int infoLev, int offset)
143     {
144
145         // Determine the information level
146

147         int pos = offset;
148
149         switch (infoLev)
150         {
151
152         // Standard information level
153

154         case InfoStandard:
155             pos += InfoStandard;
156             break;
157
158         // Standard + EA size
159

160         case InfoQueryEASize:
161             pos += InfoQueryEASizeLen;
162             break;
163
164         // File name information
165

166         case InfoNames:
167             pos += InfoNamesLen;
168             break;
169
170         // File/directory information
171

172         case InfoDirectory:
173             pos += InfoDirectoryLen;
174             break;
175
176         // File/directory information full
177

178         case InfoFullDirectory:
179             pos += InfoFullDirectoryLen;
180             break;
181
182         // Full file/directory information full plus short name
183

184         case InfoDirectoryBoth:
185             pos += InfoDirectoryBothLen;
186             break;
187         }
188
189         // Return the file name offset
190

191         return pos;
192     }
193
194     /**
195      * Calculate the required buffer space for the file information at the specified file
196      * information level.
197      *
198      * @param info File information
199      * @param infoLev File information level requested.
200      * @param resKey true if resume keys are being returned, else false.
201      * @param uni true if Unicode strings are being used, or false for ASCII strings
202      * @return int Buffer space required, or -1 if unknown information level.
203      */

204     public final static int calcInfoSize(FileInfo info, int infoLev, boolean resKey, boolean uni)
205     {
206
207         // Determine the information level requested
208

209         int len = -1;
210         int nameLen = info.getFileName().length() + 1;
211         if (uni)
212             nameLen *= 2;
213
214         switch (infoLev)
215         {
216
217         // Standard information level
218

219         case InfoStandard:
220             len = InfoStandardLen + nameLen;
221             break;
222
223         // Standard + EA size
224

225         case InfoQueryEASize:
226             len = InfoQueryEASizeLen + nameLen;
227             break;
228
229         // File name information
230

231         case InfoNames:
232             len += InfoNamesLen + nameLen;
233             break;
234
235         // File/directory information
236

237         case InfoDirectory:
238             len = InfoDirectoryLen + nameLen;
239             break;
240
241         // File/directory information full
242

243         case InfoFullDirectory:
244             len += InfoFullDirectoryLen + nameLen;
245             break;
246
247         // Full file/directory information plus short name
248

249         case InfoDirectoryBoth:
250             len = InfoDirectoryBothLen + nameLen;
251             break;
252
253         // Maacintosh information level
254

255         case InfoMacHfsInfo:
256             len = InfoMacHfsLen + nameLen;
257             break;
258         }
259
260         // Add extra space for the resume key, if enabled
261

262         if (resKey)
263             len += 4;
264
265         // Return the buffer length required.
266

267         return len;
268     }
269
270     /**
271      * Clear the next structure offset
272      *
273      * @param dataBuf DataBuffer
274      * @param level int
275      * @param offset int
276      */

277     public static final void clearNextOffset(DataBuffer buf, int level, int offset)
278     {
279
280         // Standard information level does not have a next entry offset
281

282         if (level == InfoStandard)
283             return;
284
285         // Clear the next entry offset
286

287         int curPos = buf.getPosition();
288         buf.setPosition(offset);
289         buf.putInt(0);
290         buf.setPosition(curPos);
291     }
292
293     /**
294      * Pack a file information object into the specified buffer. Use the standard information level
295      * if the EA size flag is false, else add the EA size field.
296      *
297      * @param info File information to be packed.
298      * @param buf Buffer to pack the data into.
299      * @param EAflag Add EA size field if true.
300      * @param uni Pack Unicode strings if true, else pack ASCII strings
301      */

302     protected final static void packInfoStandard(FileInfo info, DataBuffer buf, boolean EAflag, boolean uni)
303     {
304
305         // Information format :-
306
// SMB_DATE CreationDate
307
// SMB_TIME CreationTime
308
// SMB_DATE LastAccessDate
309
// SMB_TIME LastAccessTime
310
// SMB_DATE LastWriteDate
311
// SMB_TIME LastWriteTime
312
// ULONG File size
313
// ULONG Allocation size
314
// USHORT File attributes
315
// [ ULONG EA size ]
316
// UCHAR File name length
317
// STRING File name, null terminated
318

319         // Pack the creation date/time
320

321         SMBDate date = new SMBDate(0);
322
323         if (info.hasCreationDateTime())
324         {
325             date.setTime(info.getCreationDateTime());
326             buf.putShort(date.asSMBDate());
327             buf.putShort(date.asSMBTime());
328         }
329         else
330             buf.putZeros(4);
331
332         // Pack the last access date/time
333

334         if (info.hasAccessDateTime())
335         {
336             date.setTime(info.getAccessDateTime());
337             buf.putShort(date.asSMBDate());
338             buf.putShort(date.asSMBTime());
339         }
340         else
341             buf.putZeros(4);
342
343         // Pack the last write date/time
344

345         if (info.hasModifyDateTime())
346         {
347             date.setTime(info.getModifyDateTime());
348             buf.putShort(date.asSMBDate());
349             buf.putShort(date.asSMBTime());
350         }
351         else
352             buf.putZeros(4);
353
354         // Pack the file size and allocation size
355

356         buf.putInt(info.getSizeInt());
357
358         if (info.getAllocationSize() < info.getSize())
359             buf.putInt(info.getSizeInt());
360         else
361             buf.putInt(info.getAllocationSizeInt());
362
363         // Pack the file attributes
364

365         buf.putShort(info.getFileAttributes());
366
367         // Pack the EA size, always zero
368

369         if (EAflag)
370             buf.putInt(0);
371
372         // Pack the file name
373

374         if (uni == true)
375         {
376
377             // Pack the number of bytes followed by the Unicode name word aligned
378

379             buf.putByte(info.getFileName().length() * 2);
380             buf.wordAlign();
381             buf.putString(info.getFileName(), uni, true);
382         }
383         else
384         {
385
386             // Pack the number of bytes followed by the ASCII name
387

388             buf.putByte(info.getFileName().length());
389             buf.putString(info.getFileName(), uni, true);
390         }
391     }
392
393     /**
394      * Pack the file name information
395      *
396      * @param info File information to be packed.
397      * @param buf Buffer to pack the data into.
398      * @param uni Pack Unicode strings if true, else pack ASCII strings
399      */

400     protected final static void packInfoFileName(FileInfo info, DataBuffer buf, boolean uni)
401     {
402
403         // Information format :-
404
// ULONG NextEntryOffset
405
// ULONG FileIndex
406
// ULONG FileNameLength
407
// STRING FileName
408

409         // Pack the file id
410

411         int startPos = buf.getPosition();
412         buf.putZeros(4);
413         buf.putInt(EnableFileIdPacking ? info.getFileId() : 0);
414
415         // Pack the file name length
416

417         int nameLen = info.getFileName().length();
418         if (uni)
419             nameLen *= 2;
420
421         buf.putInt(nameLen);
422
423         // Pack the long file name string
424

425         buf.putString(info.getFileName(), uni, false);
426
427         // Align the buffer pointer and set the offset to the next file information entry
428

429         buf.longwordAlign();
430
431         int curPos = buf.getPosition();
432         buf.setPosition(startPos);
433         buf.putInt(curPos - startPos);
434         buf.setPosition(curPos);
435     }
436
437     /**
438      * Pack the file/directory information
439      *
440      * @param info File information to be packed.
441      * @param buf Buffer to pack the data into.
442      * @param uni Pack Unicode strings if true, else pack ASCII strings
443      */

444     protected final static void packInfoDirectory(FileInfo info, DataBuffer buf, boolean uni)
445     {
446
447         // Information format :-
448
// ULONG NextEntryOffset
449
// ULONG FileIndex
450
// LARGE_INTEGER CreationTime
451
// LARGE_INTEGER LastAccessTime
452
// LARGE_INTEGER LastWriteTime
453
// LARGE_INTEGER ChangeTime
454
// LARGE_INTEGER EndOfFile
455
// LARGE_INTEGER AllocationSize
456
// ULONG FileAttributes
457
// ULONG FileNameLength
458
// STRING FileName
459

460         // Pack the file id
461

462         int startPos = buf.getPosition();
463         buf.putZeros(4);
464         buf.putInt(EnableFileIdPacking ? info.getFileId() : 0);
465
466         // Pack the creation date/time
467

468         if (info.hasCreationDateTime())
469         {
470             buf.putLong(NTTime.toNTTime(info.getCreationDateTime()));
471         }
472         else
473             buf.putZeros(8);
474
475         // Pack the last access date/time
476

477         if (info.hasAccessDateTime())
478         {
479             buf.putLong(NTTime.toNTTime(info.getAccessDateTime()));
480         }
481         else
482             buf.putZeros(8);
483
484         // Pack the last write date/time and change time
485

486         if (info.hasModifyDateTime())
487         {
488             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
489             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
490         }
491         else
492             buf.putZeros(16);
493
494         // Pack the file size and allocation size
495

496         buf.putLong(info.getSize());
497
498         if (info.getAllocationSize() < info.getSize())
499             buf.putLong(info.getSize());
500         else
501             buf.putLong(info.getAllocationSize());
502
503         // Pack the file attributes
504

505         buf.putInt(info.getFileAttributes());
506
507         // Pack the file name length
508

509         int nameLen = info.getFileName().length();
510         if (uni)
511             nameLen *= 2;
512
513         buf.putInt(nameLen);
514
515         // Pack the long file name string
516

517         buf.putString(info.getFileName(), uni, false);
518
519         // Align the buffer pointer and set the offset to the next file information entry
520

521         buf.longwordAlign();
522
523         int curPos = buf.getPosition();
524         buf.setPosition(startPos);
525         buf.putInt(curPos - startPos);
526         buf.setPosition(curPos);
527     }
528
529     /**
530      * Pack the full file/directory information
531      *
532      * @param info File information to be packed.
533      * @param buf Buffer to pack the data into.
534      * @param uni Pack Unicode strings if true, else pack ASCII strings
535      */

536     protected final static void packInfoDirectoryFull(FileInfo info, DataBuffer buf, boolean uni)
537     {
538
539         // Information format :-
540
// ULONG NextEntryOffset
541
// ULONG FileIndex
542
// LARGE_INTEGER CreationTime
543
// LARGE_INTEGER LastAccessTime
544
// LARGE_INTEGER LastWriteTime
545
// LARGE_INTEGER ChangeTime
546
// LARGE_INTEGER EndOfFile
547
// LARGE_INTEGER AllocationSize
548
// ULONG FileAttributes
549
// ULONG FileNameLength
550
// ULONG EaSize
551
// STRING FileName
552

553         // Pack the file id
554

555         int startPos = buf.getPosition();
556         buf.putZeros(4);
557         buf.putInt(EnableFileIdPacking ? info.getFileId() : 0);
558
559         // Pack the creation date/time
560

561         if (info.hasCreationDateTime())
562         {
563             buf.putLong(NTTime.toNTTime(info.getCreationDateTime()));
564         }
565         else
566             buf.putZeros(8);
567
568         // Pack the last access date/time
569

570         if (info.hasAccessDateTime())
571         {
572             buf.putLong(NTTime.toNTTime(info.getAccessDateTime()));
573         }
574         else
575             buf.putZeros(8);
576
577         // Pack the last write date/time
578

579         if (info.hasModifyDateTime())
580         {
581             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
582             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
583         }
584         else
585             buf.putZeros(16);
586
587         // Pack the file size and allocation size
588

589         buf.putLong(info.getSize());
590
591         if (info.getAllocationSize() < info.getSize())
592             buf.putLong(info.getSize());
593         else
594             buf.putLong(info.getAllocationSize());
595
596         // Pack the file attributes
597

598         buf.putInt(info.getFileAttributes());
599
600         // Pack the file name length
601

602         int nameLen = info.getFileName().length();
603         if (uni)
604             nameLen *= 2;
605
606         buf.putInt(nameLen);
607
608         // Pack the EA size
609

610         buf.putZeros(4);
611
612         // Pack the long file name string
613

614         buf.putString(info.getFileName(), uni, false);
615
616         // Align the buffer pointer and set the offset to the next file information entry
617

618         buf.longwordAlign();
619
620         int curPos = buf.getPosition();
621         buf.setPosition(startPos);
622         buf.putInt(curPos - startPos);
623         buf.setPosition(curPos);
624     }
625
626     /**
627      * Pack the full file/directory information
628      *
629      * @param info File information to be packed.
630      * @param buf Buffer to pack the data into.
631      * @param uni Pack Unicode strings if true, else pack ASCII strings
632      */

633     protected final static void packInfoDirectoryBoth(FileInfo info, DataBuffer buf, boolean uni)
634     {
635
636         // Information format :-
637
// ULONG NextEntryOffset
638
// ULONG FileIndex
639
// LARGE_INTEGER CreationTime
640
// LARGE_INTEGER LastAccessTime
641
// LARGE_INTEGER LastWriteTime
642
// LARGE_INTEGER ChangeTime
643
// LARGE_INTEGER EndOfFile
644
// LARGE_INTEGER AllocationSize
645
// ULONG FileAttributes
646
// ULONG FileNameLength
647
// ULONG EaSize
648
// UCHAR ShortNameLength
649
// WCHAR ShortName[12]
650
// STRING FileName
651

652         // Pack the file id
653

654         int startPos = buf.getPosition();
655         buf.putZeros(4);
656         buf.putInt(EnableFileIdPacking ? info.getFileId() : 0);
657
658         // Pack the creation date/time
659

660         if (info.hasCreationDateTime())
661         {
662             buf.putLong(NTTime.toNTTime(info.getCreationDateTime()));
663         }
664         else
665             buf.putZeros(8);
666
667         // Pack the last access date/time
668

669         if (info.hasAccessDateTime())
670         {
671             buf.putLong(NTTime.toNTTime(info.getAccessDateTime()));
672         }
673         else
674             buf.putZeros(8);
675
676         // Pack the last write date/time and change time
677

678         if (info.hasModifyDateTime())
679         {
680             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
681             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
682         }
683         else
684             buf.putZeros(16);
685
686         // Pack the file size and allocation size
687

688         buf.putLong(info.getSize());
689
690         if (info.getAllocationSize() < info.getSize())
691             buf.putLong(info.getSize());
692         else
693             buf.putLong(info.getAllocationSize());
694
695         // Pack the file attributes
696

697         buf.putInt(info.getFileAttributes());
698
699         // Pack the file name length
700

701         int nameLen = info.getFileName().length();
702         if (uni)
703             nameLen *= 2;
704
705         buf.putInt(nameLen);
706
707         // Pack the EA size
708

709         buf.putZeros(4);
710
711         // Pack the short file name length (8.3 name)
712

713         pack8Dot3Name(buf, info.getFileName(), uni);
714
715         // Pack the long file name string
716

717         buf.putString(info.getFileName(), uni, false);
718
719         // Align the buffer pointer and set the offset to the next file information entry
720

721         buf.longwordAlign();
722
723         int curPos = buf.getPosition();
724         buf.setPosition(startPos);
725         buf.putInt(curPos - startPos);
726         buf.setPosition(curPos);
727     }
728
729     /**
730      * Pack the Macintosh format file/directory information
731      *
732      * @param info File information to be packed.
733      * @param buf Buffer to pack the data into.
734      * @param uni Pack Unicode strings if true, else pack ASCII strings
735      */

736     protected final static void packInfoMacHfs(FileInfo info, DataBuffer buf, boolean uni)
737     {
738
739         // Information format :-
740
// ULONG NextEntryOffset
741
// ULONG FileIndex
742
// LARGE_INTEGER CreationTime
743
// LARGE_INTEGER LastWriteTime
744
// LARGE_INTEGER ChangeTime
745
// LARGE_INTEGER Data stream length
746
// LARGE_INTEGER Resource stream length
747
// LARGE_INTEGER Data stream allocation size
748
// LARGE_INTEGER Resource stream allocation size
749
// ULONG ExtFileAttributes
750
// UCHAR FLAttrib Macintosh SetFLock, 1 = file locked
751
// UCHAR Pad
752
// UWORD DrNmFls Number of items in a directory, zero for files
753
// ULONG AccessControl
754
// UCHAR FinderInfo[32]
755
// ULONG FileNameLength
756
// UCHAR ShortNameLength
757
// UCHAR Pad
758
// WCHAR ShortName[12]
759
// STRING FileName
760
// LONG UniqueId
761

762         // Pack the file id
763

764         int startPos = buf.getPosition();
765         buf.putZeros(4);
766         buf.putInt(EnableFileIdPacking ? info.getFileId() : 0);
767
768         // Pack the creation date/time
769

770         if (info.hasCreationDateTime())
771         {
772             buf.putLong(NTTime.toNTTime(info.getCreationDateTime()));
773         }
774         else
775             buf.putZeros(8);
776
777         // Pack the last write date/time and change time
778

779         if (info.hasModifyDateTime())
780         {
781             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
782             buf.putLong(NTTime.toNTTime(info.getModifyDateTime()));
783         }
784         else
785             buf.putZeros(16);
786
787         // Pack the data stream size and resource stream size (always zero)
788

789         buf.putLong(info.getSize());
790         buf.putZeros(8);
791
792         // Pack the data stream allocation size and resource stream allocation size (always zero)
793

794         if (info.getAllocationSize() < info.getSize())
795             buf.putLong(info.getSize());
796         else
797             buf.putLong(info.getAllocationSize());
798         buf.putZeros(8);
799
800         // Pack the file attributes
801

802         buf.putInt(info.getFileAttributes());
803
804         // Pack the file lock and padding byte
805

806         buf.putZeros(2);
807
808         // Pack the number of items in a directory, always zero for now
809

810         buf.putShort(0);
811
812         // Pack the access control
813

814         buf.putInt(0);
815
816         // Pack the finder information
817

818         buf.putZeros(32);
819
820         // Pack the file name length
821

822         int nameLen = info.getFileName().length();
823         if (uni)
824             nameLen *= 2;
825
826         buf.putInt(nameLen);
827
828         // Pack the short file name length (8.3 name) and name
829

830         pack8Dot3Name(buf, info.getFileName(), uni);
831
832         // Pack the long file name string
833

834         buf.putString(info.getFileName(), uni, false);
835
836         // Pack the unique id
837

838         buf.putInt(0);
839
840         // Align the buffer pointer and set the offset to the next file information entry
841

842         buf.longwordAlign();
843
844         int curPos = buf.getPosition();
845         buf.setPosition(startPos);
846         buf.putInt(curPos - startPos);
847         buf.setPosition(curPos);
848     }
849
850     /**
851      * Pack a file name as a short 8.3 DOS style name. Packs the short name length byte, reserved
852      * byte and 8.3 file name string.
853      *
854      * @param buf DataBuffer
855      * @param fileName String
856      * @param uni boolean
857      */

858     private static final void pack8Dot3Name(DataBuffer buf, String JavaDoc fileName, boolean uni)
859     {
860
861         if (Enable8Dot3Names == false)
862         {
863
864             // Pack an emty 8.3 name structure
865

866             buf.putZeros(26);
867         }
868         else
869         {
870
871             // Split the file name string into name and extension
872

873             int pos = fileName.lastIndexOf('.');
874
875             String JavaDoc namePart = null;
876             String JavaDoc extPart = null;
877
878             if (pos != -1)
879             {
880
881                 // Split the file name string
882

883                 namePart = fileName.substring(0, pos);
884                 extPart = fileName.substring(pos + 1);
885             }
886             else
887                 namePart = fileName;
888
889             // If the name already fits into an 8.3 name we do not need to pack the short name
890

891             if (namePart.length() <= 8 && (extPart == null || extPart.length() <= 3))
892             {
893
894                 // Pack an emty 8.3 name structure
895

896                 buf.putZeros(26);
897                 return;
898             }
899
900             // Truncate the name and extension parts down to 8.3 sizes
901

902             if (namePart.length() > 8)
903                 namePart = namePart.substring(0, 6) + "~1";
904
905             if (extPart != null && extPart.length() > 3)
906                 extPart = extPart.substring(0, 3);
907
908             // Build the 8.3 format string
909

910             StringBuffer JavaDoc str = new StringBuffer JavaDoc(16);
911
912             str.append(namePart);
913             while (str.length() < 8)
914                 str.append(" ");
915
916             if (extPart != null)
917             {
918                 str.append(".");
919                 str.append(extPart);
920             }
921             else
922                 str.append(" ");
923
924             // Space pad the string to 12 characters
925

926             while (str.length() < 12)
927                 str.append(" ");
928
929             // Calculate the used length
930

931             int len = namePart.length();
932             if (extPart != null)
933                 len = extPart.length() + 9;
934
935             len *= 2;
936
937             // Pack the 8.3 file name structure, always packed as Unicode
938

939             buf.putByte(len);
940             buf.putByte(0);
941
942             buf.putString(str.toString(), true, false);
943         }
944     }
945 }
Popular Tags