Permalink
Browse files

Initial commit.

  • Loading branch information...
kohanyirobert committed Jan 22, 2012
0 parents commit d910fcae55ae19f456f896dfa981e1ff2f8bb4d7
Showing with 2,903 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +19 −0 LICENSE.txt
  3. +107 −0 README.md
  4. +184 −0 pom.xml
  5. +178 −0 src/main/java/com/github/kohanyirobert/ebson/BsonBinary.java
  6. +168 −0 src/main/java/com/github/kohanyirobert/ebson/BsonBytes.java
  7. +250 −0 src/main/java/com/github/kohanyirobert/ebson/BsonDocument.java
  8. +259 −0 src/main/java/com/github/kohanyirobert/ebson/BsonDocuments.java
  9. +292 −0 src/main/java/com/github/kohanyirobert/ebson/BsonObject.java
  10. +28 −0 src/main/java/com/github/kohanyirobert/ebson/BsonPreconditions.java
  11. +30 −0 src/main/java/com/github/kohanyirobert/ebson/BsonReader.java
  12. +78 −0 src/main/java/com/github/kohanyirobert/ebson/BsonToken.java
  13. +27 −0 src/main/java/com/github/kohanyirobert/ebson/BsonWriter.java
  14. +63 −0 src/main/java/com/github/kohanyirobert/ebson/DefaultDocument.java
  15. +44 −0 src/main/java/com/github/kohanyirobert/ebson/DefaultDocumentBuilder.java
  16. +132 −0 src/main/java/com/github/kohanyirobert/ebson/DefaultPredicate.java
  17. +200 −0 src/main/java/com/github/kohanyirobert/ebson/DefaultReader.java
  18. +179 −0 src/main/java/com/github/kohanyirobert/ebson/DefaultWriter.java
  19. +8 −0 src/main/java/com/github/kohanyirobert/ebson/package-info.java
  20. +17 −0 src/test/java/com/github/kohanyirobert/ebson/AbstractBsonTest.java
  21. +28 −0 src/test/java/com/github/kohanyirobert/ebson/AbstractReaderWriterTest.java
  22. +48 −0 src/test/java/com/github/kohanyirobert/ebson/BsonDocumentTest.java
  23. +135 −0 src/test/java/com/github/kohanyirobert/ebson/BsonDocumentsTest.java
  24. +73 −0 src/test/java/com/github/kohanyirobert/ebson/BsonEncodingTest.java
  25. +62 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultArrayReaderWriterTest.java
  26. +26 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultBinaryReaderWriterTest.java
  27. +22 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultBooleanReaderWriterTest.java
  28. +22 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultDoubleReaderWriterTest.java
  29. +19 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultFieldReaderWriterTest.java
  30. +22 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultInt32ReaderWriterTest.java
  31. +22 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultInt64ReaderWriterTest.java
  32. +25 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultKeyReaderWriterTest.java
  33. +17 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultNullReaderWriterTest.java
  34. +99 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultRegularExpressionReaderWriterTest.java
  35. +19 −0 src/test/java/com/github/kohanyirobert/ebson/DefaultUtcDateTimeReaderWriterTest.java
@@ -0,0 +1 @@
+*
@@ -0,0 +1,19 @@
+Copyright (C) 2011-2012 by Kohányi Róbert <kohanyi.robert@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
107 README.md
@@ -0,0 +1,107 @@
+# ebson
+`ebson` is an extensible [BSON][] encoder/decoder library written in Java. The
+library is extensible in the sense that the mappings between Java and BSON types
+are configurable and the logic to serialize custom Java types is pluggable. Its
+single dependency is the [Guava libraries][] by Google.
+
+## License
+Released under the permissive [MIT License][].
+
+## Author
+[Kohányi Róbert][].
+
+## Download
+Add the library as a dependency in your project's *pom.xml* like this.
+
+```xml
+<dependency>
+ <groupId>com.github.kohanyirobert</groupId>
+ <artifactId>ebson</artifactId>
+ <version>...</version>
+</dependency>
+```
+
+Releases and snapshots are deployed to [Sonatype's][] [OSS repository][] (and
+synced to the [Central Maven Repository][] from there). To download JARs from
+Sonatype's repository include the following repository tag inside your Maven
+installation's *settings.xml* or your project's *pom.xml*.
+
+```xml
+<repository>
+ <id>sonatype-oss<id>
+ <url>https://oss.sonatype.org/content/groups/public</url>
+</repository>
+```
+
+## Build
+As the project is managed with [Maven][] you simply clone it and issue *mvn
+install* or *mvn package* inside the clone's directory.
+
+```
+git clone git://github.com/kohanyirobert/ebson.git
+cd ebson/
+mvn package
+# and/or
+mvn install
+```
+
+## Usage
+### Serialization
+```java
+// create documents to serialize
+BsonDocument document = BsonDocuments.of("key", new Date());
+
+// grab a little-endian byte buffer
+ByteBuffer buffer = ByteBuffer.allocate(32).order(ByteOrder.LITTLE_ENDIAN);
+
+// use the documents utility class to write the document into the buffer
+BsonDocuments.writeTo(buffer, document);
+
+// use the serialized data
+buffer.flip();
+```
+
+### Deserialization
+```java
+// given the previous buffer
+BsonDocument newDocument = BsonDocuments.readFrom(buffer);
+
+// prints true
+System.out.println(document.equals(newDocument));
+```
+
+### Extensibility
+```java
+// to use joda-time's date-time instead of java's date supply
+// a predicate (to test whether an input class is compatible with
+// date-time or not) for the appropriate bson type
+BsonObject.UTC_DATE_TIME.predicate(new Predicate<Class<?>>() {
+ @Override public boolean apply(Class<?> input) {
+ return input == null ? false : DateTime.class.isAssignableFrom(input);
+ }
+});
+
+// register a writer with the same bson type which is
+// able to serialize date-times into byte buffers
+BsonObject.UTC_DATE_TIME.writer(new BsonWriter() {
+ @Override public void writeTo(ByteBuffer buffer, Object reference) {
+ buffer.putLong(((DateTime) reference).getMillis());
+ }
+});
+
+// finally register a reader to do all this ass backwards
+BsonObject.UTC_DATE_TIME.reader(new BsonReader() {
+ @Override public Object readFrom(ByteBuffer buffer) {
+ return new DateTime(buffer.getLong());
+ }
+});
+```
+
+[BSON]: http://bsonspec.org
+[Guava libraries]: http://code.google.com/p/guava-libraries
+[Kohányi Róbert]: http://kohanyirobert.github.com
+[MIT License]: https://raw.github.com/kohanyirobert/ebson/master/LICENSE.txt
+[Sonatype's]: http://sonatype.com
+[OSS repository]: https://oss.sonatype.org
+[Central Maven Repository]: http://search.maven.org
+[Maven]: http://maven.apache.org
184 pom.xml
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.github.kohanyirobert</groupId>
+ <artifactId>ebson</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+
+ <name>Extensible Java BSON encoder/decoder library.</name>
+ <description>
+ Extensible BSON encoder/decoder library written
+ in Java with pluggable Java-to-BSON type mappings.
+ </description>
+ <url>https://github.com/kohanyirobert/ebson</url>
+
+ <licenses>
+ <license>
+ <name>MIT License</name>
+ <url>LICENSE.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:git:git@github.com:kohanyirobert/ebson.git</connection>
+ <developerConnection>scm:git:git@github.com:kohanyirobert/ebson.git</developerConnection>
+ <url>git@github.com:kohanyirobert/ebson.git</url>
+ </scm>
+
+ <distributionManagement>
+ <repository>
+ <id>sonatype-nexus-staging</id>
+ <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+ </repository>
+ <snapshotRepository>
+ <id>sonatype-nexus-snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
+ </snapshotRepository>
+ </distributionManagement>
+
+ <developers>
+ <developer>
+ <id>kohanyi.robert</id>
+ <name>Kohányi Róbert</name>
+ <email>kohanyi.robert@gmail.com</email>
+ <roles>
+ <role>owner</role>
+ <role>developer</role>
+ </roles>
+ <timezone>+1</timezone>
+ </developer>
+ </developers>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>11.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>2.7.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${basedir}</directory>
+ <targetPath>${project.build.outputDirectory}/META-INF</targetPath>
+ <filtering>false</filtering>
+ <includes>
+ <include>LICENSE.txt</include>
+ <include>README.md</include>
+ </includes>
+ </resource>
+ </resources>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.1.2</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.8</version>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <links>
+ <link>http://docs.guava-libraries.googlecode.com/git/javadoc</link>
+ </links>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>2.8</version>
+ <executions>
+ <execution>
+ <id>checkstyle-main</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <configLocation>https://raw.github.com/kohanyirobert/checkstyle/master/checkstyle-main.xml</configLocation>
+ </configuration>
+ </execution>
+ <execution>
+ <id>checkstyle-test</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <configLocation>https://raw.github.com/kohanyirobert/checkstyle/master/checkstyle-test.xml</configLocation>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <consoleOutput>true</consoleOutput>
+ <failsOnError>true</failsOnError>
+ <linkXRef>false</linkXRef>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.4</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Oops, something went wrong.

0 comments on commit d910fca

Please sign in to comment.