Source code: com/yaftp/utils/DataStructure.java
1 /**
2 *
3 * CopyRights Jean-Yves MENGANT 1999,2000,2001,2002
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package com.yaftp.utils ;
21
22 /**
23
24 The class below implements data containers facilities
25 for heterogenous data types embedded into byte arrays
26
27 // Constructor
28 public DataStructure( byte Origin[] ,
29 int Offset ,
30 int Size
31 )
32 // CopyBack
33 public void CopyFrom( byte Origin[] , int Size )
34 // Copy To
35 public void CopyTo( byte Dest[] , int Size )
36 // Byte Accessor
37 public int GiveElem( int Ii )
38 // Is there a data container defined
39 public boolean ContainerExists()
40
41 @author Jean-Yves MENGANT
42 */
43
44 public class DataStructure {
45
46 // Define the UNICODE Iso_Latin1 encoding identifier
47 public final static String ISO_LATIN_1 = "8859_1" ;
48
49 protected byte _Struct[] ; // Origin of data structure
50 protected int _Offset ; // offset of child data
51 protected int _Size ; // Size in byte starting at _Offset
52
53
54 // Public access starts here
55
56 // Construct using an existing byte array(Supose to point on
57 // a valid packed decimal format
58 public DataStructure( byte Origin[] ,
59 int Offset ,
60 int Size
61 )
62 {
63 _Struct = Origin ; // Point On user array
64 _Size = Size ;
65 _Offset = Offset ;
66 }
67
68 // CopyBack
69 public void CopyFrom( byte Origin[] , int Size )
70 {
71 if ( _Struct != null )
72 System.arraycopy( Origin , 0 , _Struct , _Offset , Size ) ;
73 }
74
75 // Copy To
76 public void CopyTo( byte Dest[] , int Size )
77 {
78 if ( _Struct != null )
79 System.arraycopy( _Struct , _Offset , Dest , 0 , Size ) ;
80 }
81
82 // Byte Accessor
83 public int GiveElem( int Ii )
84 { return ( _Struct[Ii+_Offset] ) ; }
85
86 // Byte Actuator ( set element Ii to byte Value )
87 public void SetElem( int Ii , byte Value )
88 { _Struct[Ii+_Offset] = Value ; }
89
90 // Is there a data container defined
91 public boolean ContainerExists()
92 { return ( _Struct != null ) ; }
93
94 // Just use the main method for Class unit testing
95 public static void main ( String Argv[] )
96 {
97
98 }
99
100 }