Skip to content

Commit

Permalink
Added comments and usage information for the Java SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Apr 5, 2017
1 parent 8f994ef commit 4aca82f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
22 changes: 22 additions & 0 deletions java-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@ dependencies {
}
```
Usually, you only need to include the schemas you actually need in your dependencies.

The generated code each refers to a single schema. The classes of Avro records will extend `org.apache.avro.specific.SpecificRecord`. They each have a static `getClassSchema()` function that returns the `Schema` that it was generated from. To read JSON serialized data for example, use the following code:

```java
public class Deserialize {
public static void main(String args[]) throws Exception {
//Instantiating the Schema.Parser class.
DatumReader<PhoneBatteryLevel> datumReader = new SpecificDatumReader<>(PhoneBatteryLevel.class);
DataFileReader<PhoneBatteryLevel> dataFileReader = new DataFileReader<>(new File("/path/to/mydata.avro"), datumReader);

System.out.println("Reading phone battery levels");
PhoneBatteryLevel batteryLevel = null;
while (dataFileReader.hasNext()) {
batteryLevel = dataFileReader.next(batteryLevel);
System.out.println("Phone battery level: " + batteryLevel);
}
System.out.println("Done");
}
}
```

Alternatively, use `org.radarcns.data.SpecificRecordEncoder` and `org.radarcns.data.SpecificRecordDecoder` from the `radar-commons` package.
11 changes: 4 additions & 7 deletions java-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ subprojects {
apply plugin: 'com.commercehub.gradle.plugin.avro-base'
apply plugin: 'maven-publish'

// Configuration
version = '0.1'
group = 'org.radarcns'
ext.githubRepo = 'RADAR-CNS/RADAR-Schemas'
Expand All @@ -27,15 +28,16 @@ subprojects {
ext.issueUrl = 'https://github.com/' + githubRepo + '/issues'
ext.website = 'http://radar-cns.org'

// dependencies
repositories {
jcenter()
maven { url 'http://dl.bintray.com/typesafe/maven-releases' }
}

dependencies {
api group: 'org.apache.avro', name: 'avro', version: avroVersion
}

// publishing
ext.pomConfig = {
licenses {
license {
Expand Down Expand Up @@ -103,19 +105,14 @@ subprojects {
archives sourcesJar, javadocJar
}

// Generated avro files
ext.avroOutputDir = file('src/main/java')

clean {
delete avroOutputDir
}
}

//---------------------------------------------------------------------------//
// Testing //
//---------------------------------------------------------------------------//



task wrapper(type: Wrapper) {
gradleVersion = '3.4.1'
distributionUrl distributionUrl.replace("bin", "all")
Expand Down

0 comments on commit 4aca82f

Please sign in to comment.