|
24 | 24 | import java.util.*; |
25 | 25 | import java.util.logging.*; |
26 | 26 |
|
| 27 | +import org.bson.*; |
| 28 | + |
27 | 29 | /** |
28 | 30 | * Handles byte functions for <code>ByteEncoder</code> and <code>ByteDecoder</code>. |
29 | 31 | */ |
30 | | -public class Bytes { |
| 32 | +public class Bytes extends BSON { |
31 | 33 |
|
32 | 34 | static Logger LOGGER = Logger.getLogger( "com.mongodb" ); |
33 | 35 |
|
@@ -63,32 +65,6 @@ public class Bytes { |
63 | 65 | NUM_ENCODERS = numBufs; |
64 | 66 | } |
65 | 67 |
|
66 | | - static final byte EOO = 0; |
67 | | - static final byte NUMBER = 1; |
68 | | - static final byte STRING = 2; |
69 | | - static final byte OBJECT = 3; |
70 | | - static final byte ARRAY = 4; |
71 | | - static final byte BINARY = 5; |
72 | | - static final byte UNDEFINED = 6; |
73 | | - static final byte OID = 7; |
74 | | - static final byte BOOLEAN = 8; |
75 | | - static final byte DATE = 9; |
76 | | - static final byte NULL = 10; |
77 | | - static final byte REGEX = 11; |
78 | | - static final byte REF = 12; |
79 | | - static final byte CODE = 13; |
80 | | - static final byte SYMBOL = 14; |
81 | | - static final byte CODE_W_SCOPE = 15; |
82 | | - static final byte NUMBER_INT = 16; |
83 | | - static final byte TIMESTAMP = 17; |
84 | | - static final byte NUMBER_LONG = 18; |
85 | | - |
86 | | - static final byte MINKEY = -1; |
87 | | - static final byte MAXKEY = 127; |
88 | | - |
89 | | - private static final int GLOBAL_FLAG = 256; |
90 | | - |
91 | | - |
92 | 68 | /* |
93 | 69 | these are binary types |
94 | 70 | so the format would look like |
@@ -154,98 +130,6 @@ public static byte getType( Object o ){ |
154 | 130 | return 0; |
155 | 131 | } |
156 | 132 |
|
157 | | - /** Converts a string of regular expression flags from the database in Java regular |
158 | | - * expression flags. |
159 | | - * @param flags flags from database |
160 | | - * @return the Java flags |
161 | | - */ |
162 | | - public static int patternFlags( String flags ){ |
163 | | - flags = flags.toLowerCase(); |
164 | | - int fint = 0; |
165 | | - |
166 | | - for( int i=0; i<flags.length(); i++ ) { |
167 | | - Flag flag = Flag.getByCharacter( flags.charAt( i ) ); |
168 | | - if( flag != null ) { |
169 | | - fint |= flag.javaFlag; |
170 | | - if( flag.unsupported != null ) |
171 | | - _warnUnsupported( flag.unsupported ); |
172 | | - } |
173 | | - else { |
174 | | - throw new IllegalArgumentException( "unrecognized flag: "+flags.charAt( i ) ); |
175 | | - } |
176 | | - } |
177 | | - return fint; |
178 | | - } |
179 | | - |
180 | | - public static int getFlag( char c ){ |
181 | | - Flag flag = Flag.getByCharacter( c ); |
182 | | - if ( flag == null ) |
183 | | - throw new IllegalArgumentException( "unrecognized flag: " + c ); |
184 | | - |
185 | | - if ( flag.unsupported != null ){ |
186 | | - _warnUnsupported( flag.unsupported ); |
187 | | - return 0; |
188 | | - } |
189 | | - |
190 | | - return flag.javaFlag; |
191 | | - } |
192 | | - |
193 | | - /** Converts Java regular expression flags into a string of flags for the database |
194 | | - * @param flags Java flags |
195 | | - * @return the flags for the database |
196 | | - */ |
197 | | - public static String patternFlags( int flags ){ |
198 | | - StringBuilder buf = new StringBuilder(); |
199 | | - |
200 | | - for( Flag flag : Flag.values() ) { |
201 | | - if( ( flags & flag.javaFlag ) > 0 ) { |
202 | | - buf.append( flag.flagChar ); |
203 | | - flags -= flag.javaFlag; |
204 | | - } |
205 | | - } |
206 | | - |
207 | | - if( flags > 0 ) |
208 | | - throw new IllegalArgumentException( "some flags could not be recognized." ); |
209 | | - |
210 | | - return buf.toString(); |
211 | | - } |
212 | | - |
213 | | - private static enum Flag { |
214 | | - CANON_EQ( Pattern.CANON_EQ, 'c', "Pattern.CANON_EQ" ), |
215 | | - UNIX_LINES(Pattern.UNIX_LINES, 'd', "Pattern.UNIX_LINES" ), |
216 | | - GLOBAL( GLOBAL_FLAG, 'g', null ), |
217 | | - CASE_INSENSITIVE( Pattern.CASE_INSENSITIVE, 'i', null ), |
218 | | - MULTILINE(Pattern.MULTILINE, 'm', null ), |
219 | | - DOTALL( Pattern.DOTALL, 's', "Pattern.DOTALL" ), |
220 | | - LITERAL( Pattern.LITERAL, 't', "Pattern.LITERAL" ), |
221 | | - UNICODE_CASE( Pattern.UNICODE_CASE, 'u', "Pattern.UNICODE_CASE" ), |
222 | | - COMMENTS( Pattern.COMMENTS, 'x', null ); |
223 | | - |
224 | | - private static final Map<Character, Flag> byCharacter = new HashMap<Character, Flag>(); |
225 | | - |
226 | | - static { |
227 | | - for (Flag flag : values()) { |
228 | | - byCharacter.put(flag.flagChar, flag); |
229 | | - } |
230 | | - } |
231 | | - |
232 | | - public static Flag getByCharacter(char ch) { |
233 | | - return byCharacter.get(ch); |
234 | | - } |
235 | | - public final int javaFlag; |
236 | | - public final char flagChar; |
237 | | - public final String unsupported; |
238 | | - Flag( int f, char ch, String u ) { |
239 | | - javaFlag = f; |
240 | | - flagChar = ch; |
241 | | - unsupported = u; |
242 | | - } |
243 | | - } |
244 | | - |
245 | | - private static void _warnUnsupported( String flag ) { |
246 | | - System.out.println( "flag " + flag + " not supported by db." ); |
247 | | - } |
248 | | - |
249 | 133 | public static void addEncodingHook( Class c , Transformer t ){ |
250 | 134 | _anyHooks = true; |
251 | 135 | List<Transformer> l = _encodingHooks.get( c ); |
|
0 commit comments