/src/main/com/mongodb/Bytes.java

https://github.com/tqthe/mongo-java-driver · Java · 109 lines · 58 code · 29 blank · 22 comment · 15 complexity · 12dd75fe83e140ca1cdfca2bcb47f826 MD5 · raw file

  1. // Bytes.java
  2. /**
  3. * Copyright (C) 2008 10gen Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.mongodb;
  18. import java.nio.*;
  19. import java.nio.charset.*;
  20. import java.util.regex.Pattern;
  21. import java.util.*;
  22. import java.util.logging.*;
  23. import org.bson.*;
  24. import org.bson.types.*;
  25. public class Bytes extends BSON {
  26. static Logger LOGGER = Logger.getLogger( "com.mongodb" );
  27. static final boolean D = Boolean.getBoolean( "DEBUG.MONGO" );
  28. static {
  29. if ( LOGGER.getLevel() == null ){
  30. if ( D )
  31. LOGGER.setLevel( Level.ALL );
  32. else
  33. LOGGER.setLevel( Level.WARNING );
  34. }
  35. }
  36. /** Little-endian */
  37. public static final ByteOrder ORDER = ByteOrder.LITTLE_ENDIAN;
  38. static final int MAX_OBJECT_SIZE = 1024 * 1024 * 4;
  39. static final int CONNECTIONS_PER_HOST = Integer.parseInt( System.getProperty( "MONGO.POOLSIZE" , "10" ) );
  40. // --- network protocol options
  41. public static final int QUERYOPTION_TAILABLE = 1 << 1;
  42. public static final int QUERYOPTION_SLAVEOK = 1 << 2;
  43. public static final int QUERYOPTION_OPLOGREPLAY = 1 << 3;
  44. public static final int QUERYOPTION_NOTIMEOUT = 1 << 4;
  45. public static final int QUERYOPTION_AWAITDATA = 1 << 5;
  46. public static final int RESULTFLAG_CURSORNOTFOUND = 1;
  47. public static final int RESULTFLAG_ERRSET = 2;
  48. public static final int RESULTFLAG_SHARDCONFIGSTALE = 4;
  49. public static final int RESULTFLAG_AWAITCAPABLE = 8;
  50. /** Gets the type byte for a given object.
  51. * @param o the object
  52. * @return the byte value associated with the type, or 0 if <code>o</code> was <code>null</code>
  53. */
  54. public static byte getType( Object o ){
  55. if ( o == null )
  56. return NULL;
  57. if ( o instanceof DBPointer )
  58. return REF;
  59. if ( o instanceof Number )
  60. return NUMBER;
  61. if ( o instanceof String )
  62. return STRING;
  63. if ( o instanceof java.util.List )
  64. return ARRAY;
  65. if ( o instanceof byte[] )
  66. return BINARY;
  67. if ( o instanceof ObjectId )
  68. return OID;
  69. if ( o instanceof Boolean )
  70. return BOOLEAN;
  71. if ( o instanceof java.util.Date )
  72. return DATE;
  73. if ( o instanceof java.util.regex.Pattern )
  74. return REGEX;
  75. if ( o instanceof DBObject )
  76. return OBJECT;
  77. return 0;
  78. }
  79. static final ObjectId COLLECTION_REF_ID = new ObjectId( -1 , -1 , -1 );
  80. }