diff --git a/java-sdk/README.md b/java-sdk/README.md index 60552550..92b34160 100644 --- a/java-sdk/README.md +++ b/java-sdk/README.md @@ -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 datumReader = new SpecificDatumReader<>(PhoneBatteryLevel.class); + DataFileReader 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. diff --git a/java-sdk/build.gradle b/java-sdk/build.gradle index c11819ab..e17f3c60 100644 --- a/java-sdk/build.gradle +++ b/java-sdk/build.gradle @@ -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' @@ -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 { @@ -103,6 +105,7 @@ subprojects { archives sourcesJar, javadocJar } + // Generated avro files ext.avroOutputDir = file('src/main/java') clean { @@ -110,12 +113,6 @@ subprojects { } } -//---------------------------------------------------------------------------// -// Testing // -//---------------------------------------------------------------------------// - - - task wrapper(type: Wrapper) { gradleVersion = '3.4.1' distributionUrl distributionUrl.replace("bin", "all")