GeezerVison is showing github.com — Switch to okhttp 3 for HTTP and WS · einsnull/java-sdk@1d2f74b
File treeExpand file treeCollapse file tree Open diff view settings java/com/ibm/watson/developer_cloud
java/com/ibm/watson/developer_cloud natural_language_classifier/v1 relationship_extraction/v1_beta visual_insights/v1_experimental visual_recognition/v2_beta
test/java/com/ibm/watson/developer_cloud
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: README.md +4-4Lines changed: 4 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,13 +47,13 @@ APIs and SDKs that use cognitive computing to solve complex problems. | 47 | 47 | <dependency> | 48 | 48 | <groupId>com.ibm.watson.developer_cloud</groupId> | 49 | 49 | <artifactId>java-sdk</artifactId> | 50 | | - <version>2.10.0</version> | | 50 | + <version>3.0.0</version> | 51 | 51 | </dependency> | 52 | 52 | ``` | 53 | 53 | ##### Gradle | 54 | 54 |
| 55 | 55 | ```gradle | 56 | | -'com.ibm.watson.developer_cloud:java-sdk:2.10.0' | | 56 | +'com.ibm.watson.developer_cloud:java-sdk:3.0.0' | 57 | 57 | ``` | 58 | 58 |
| 59 | 59 | Now, you are ready to see some [examples](https://github.com/watson-developer-cloud/java-sdk/tree/master/examples/java/com/ibm/watson/developer_cloud). | @@ -454,7 +454,7 @@ Gradle: | 454 | 454 |
| 455 | 455 | ```sh | 456 | 456 | $ cd java-sdk | 457 | | - $ gradle jar # build jar file (build/libs/watson-developer-cloud-2.10.0.jar) | | 457 | + $ gradle jar # build jar file (build/libs/watson-developer-cloud-3.0.0.jar) | 458 | 458 | $ gradle test # run tests | 459 | 459 | ``` | 460 | 460 |
| @@ -524,4 +524,4 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md). | 524 | 524 | [apache_maven]: http://maven.apache.org/ | 525 | 525 | [releases]: https://github.com/watson-developer-cloud/java-sdk/releases | 526 | 526 |
| 527 | | -[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-2.10.0/java-sdk-2.10.0-jar-with-dependencies.jar | | 527 | +[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-3.0.0/java-sdk-3.0.0-jar-with-dependencies.jar |
Collapse file Copy file name to clipboardExpand all lines: build.gradle +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,20 +7,20 @@ sourceCompatibility = 1.6 | 7 | 7 | targetCompatibility = 1.6 | 8 | 8 | group = 'com.ibm.watson.developercloud' | 9 | 9 | archivesBaseName = 'watson-developer-cloud' | 10 | | -version = '2.10.0' | | 10 | +version = '3.0.0' | 11 | 11 |
| 12 | 12 | description = 'Client library to use the IBM Watson Services and AlchemyAPI' | 13 | 13 |
| 14 | 14 | repositories { | 15 | 15 | mavenCentral() | 16 | 16 | } | 17 | 17 | dependencies { | 18 | | - compile group: 'com.squareup.okhttp', name: 'okhttp', version:'2.7.2' | 19 | 18 | compile group: 'com.squareup.okhttp3', name: 'okhttp', version:'3.2.0' | | 19 | + compile group: 'com.squareup.okhttp3', name: 'okhttp-ws', version:'3.2.0' | 20 | 20 | compile group: 'com.squareup.okhttp3', name: 'okhttp-urlconnection', version:'3.2.0' | 21 | 21 | compile group: 'com.google.code.gson', name: 'gson', version:'2.6.2' | 22 | 22 | compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.4' | 23 | | - compile group: 'com.neovisionaries', name: 'nv-websocket-client', version:'1.22' | | 23 | + testCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version:'3.2.0' | 24 | 24 | testCompile group: 'org.mock-server', name: 'mockserver-netty', version:'3.9.17' | 25 | 25 | testCompile group: 'junit', name: 'junit-dep', version:'4.11' | 26 | 26 | } | |
Collapse file Copy file name to clipboardExpand all lines: examples/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetNewsDocumentExample.java +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -45,6 +45,7 @@ public static void main(String[] args) { | 45 | 45 | params.put(AlchemyDataNews.START, "1440720000"); | 46 | 46 | params.put(AlchemyDataNews.END, "1441407600"); | 47 | 47 | params.put(AlchemyDataNews.COUNT, 7); | | 48 | + | 48 | 49 | //Query on adjacent nested fields: | 49 | 50 | params.put("q.enriched.url.enrichedTitle.entities.entity", "|text=IBM,type=company|"); | 50 | 51 | params.put("q.enriched.url.enrichedTitle.docSentiment.type", "positive"); | |
Collapse file Copy file name to clipboardExpand all lines: examples/java/com/ibm/watson/developer_cloud/alchemy_language/v1/AlchemyLanguageExample.java +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 |
| 20 | 20 | import com.ibm.watson.developer_cloud.alchemy.v1.AlchemyLanguage; | 21 | 21 | import com.ibm.watson.developer_cloud.alchemy.v1.model.DocumentSentiment; | | 22 | +import com.ibm.watson.developer_cloud.alchemy.v1.model.Entities; | 22 | 23 |
| 23 | 24 | public class AlchemyLanguageExample { | 24 | 25 |
| @@ -29,9 +30,13 @@ public static void main(String[] args) { | 29 | 30 | Map<String, Object> params = new HashMap<String, Object>(); | 30 | 31 | params.put(AlchemyLanguage.TEXT, | 31 | 32 | "IBM Watson won the Jeopardy television show hosted by Alex Trebek"); | 32 | | - DocumentSentiment sentiment = service.getSentiment(params).execute(); | 33 | 33 |
| 34 | | - System.out.println(sentiment); | | 34 | + DocumentSentiment sentiment = service.getSentiment(params).execute(); | | 35 | + System.out.println("Sentiment: " + sentiment); | | 36 | + | | 37 | + Entities entities = service.getEntities(params).execute(); | | 38 | + System.out.println("Entities: " + entities); | | 39 | + | 35 | 40 | } | 36 | 41 |
| 37 | 42 | } |
Collapse file Copy file name to clipboardExpand all lines: examples/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateASolrClusterExample.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,7 +40,7 @@ public static void main(String[] args) throws InterruptedException { | 40 | 40 | } | 41 | 41 |
| 42 | 42 | // 3 list Solr Clusters | 43 | | - System.out.println("Solr clusters: " + service.getSolrClusters()); | | 43 | + System.out.println("Solr clusters: " + service.getSolrClusters().execute()); | 44 | 44 |
| 45 | 45 | } | 46 | 46 | } |
Collapse file Copy file name to clipboardExpand all lines: examples/java/com/ibm/watson/developer_cloud/speech_to_text/v1/RecognizeUsingWebSocketsExample.java +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 | import com.ibm.watson.developer_cloud.http.HttpMediaType; | 9 | 9 | import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults; | 10 | | -import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeDelegate; | | 10 | +import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeCallback; | 11 | 11 |
| 12 | 12 | /** | 13 | 13 | * Recognize using WebSockets a sample wav file and print the transcript into the console output. | @@ -24,15 +24,15 @@ public static void main(String[] args) throws FileNotFoundException, Interrupted | 24 | 24 | RecognizeOptions options = new RecognizeOptions(); | 25 | 25 | options.continuous(true).interimResults(true).contentType(HttpMediaType.AUDIO_WAV); | 26 | 26 |
| 27 | | - service.recognizeUsingWebSockets(audio, options, new BaseRecognizeDelegate() { | | 27 | + service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() { | 28 | 28 | @Override | 29 | | - public void onMessage(SpeechResults speechResults) { | | 29 | + public void onTranscription(SpeechResults speechResults) { | 30 | 30 | System.out.println(speechResults); | 31 | 31 | if (speechResults.isFinal()) | 32 | 32 | lock.countDown(); | 33 | 33 | } | 34 | 34 | }); | 35 | 35 |
| 36 | | - lock.await(20000, TimeUnit.MILLISECONDS); | | 36 | + lock.await(1, TimeUnit.MINUTES); | 37 | 37 | } | 38 | 38 | } |
Collapse file Copy file name to clipboardExpand all lines: examples/java/com/ibm/watson/developer_cloud/text_to_speech/v1/TextToSpeechExample.java +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 |
| 16 | 16 | import java.util.List; | 17 | 17 |
| 18 | | -import com.ibm.watson.developer_cloud.WatsonServiceTest; | 19 | 18 | import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice; | 20 | 19 |
| 21 | | -public class TextToSpeechExample extends WatsonServiceTest { | | 20 | +public class TextToSpeechExample { | 22 | 21 |
| 23 | 22 |
| 24 | 23 | public static void main(String[] args) { | |
Collapse file Copy file name to clipboardExpand all lines: examples/java/com/ibm/watson/developer_cloud/text_to_speech/v1/TranslateAndSynthesizeExample.java +22-4Lines changed: 22 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package com.ibm.watson.developer_cloud.text_to_speech.v1; | 2 | 2 |
| | 3 | +import java.io.File; | | 4 | +import java.io.FileOutputStream; | 3 | 5 | import java.io.IOException; | 4 | 6 | import java.io.InputStream; | 5 | | -import java.nio.file.Files; | 6 | | -import java.nio.file.Paths; | 7 | | -import java.nio.file.StandardCopyOption; | | 7 | +import java.io.OutputStream; | 8 | 8 |
| 9 | 9 | import com.ibm.watson.developer_cloud.language_translation.v2.LanguageTranslation; | 10 | 10 | import com.ibm.watson.developer_cloud.language_translation.v2.model.Language; | 11 | 11 | import com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult; | 12 | 12 | import com.ibm.watson.developer_cloud.text_to_speech.v1.model.AudioFormat; | 13 | 13 | import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice; | | 14 | +import com.ibm.watson.developer_cloud.text_to_speech.v1.util.WaveUtils; | 14 | 15 |
| 15 | 16 | public class TranslateAndSynthesizeExample { | 16 | 17 |
| @@ -29,7 +30,24 @@ public static void main(String[] args) throws IOException { | 29 | 30 |
| 30 | 31 | // synthesize | 31 | 32 | InputStream in = synthesizer.synthesize(translation, Voice.ES_LAURA, AudioFormat.WAV).execute(); | 32 | | - Files.copy(in, Paths.get("output.wav"), StandardCopyOption.REPLACE_EXISTING); | | 33 | + writeToFile(WaveUtils.reWriteWaveHeader(in), new File("output.wav")); | | 34 | + } | 33 | 35 |
| | 36 | + /** | | 37 | + * Write the input stream to a file | | 38 | + */ | | 39 | + private static void writeToFile(InputStream in, File file) { | | 40 | + try { | | 41 | + OutputStream out = new FileOutputStream(file); | | 42 | + byte[] buf = new byte[1024]; | | 43 | + int len; | | 44 | + while ((len = in.read(buf)) > 0) { | | 45 | + out.write(buf, 0, len); | | 46 | + } | | 47 | + out.close(); | | 48 | + in.close(); | | 49 | + } catch (Exception e) { | | 50 | + e.printStackTrace(); | | 51 | + } | 34 | 52 | } | 35 | 53 | } |
Collapse file Copy file name to clipboardExpand all lines: examples/java/com/ibm/watson/developer_cloud/tradeoff_analytics/v1/TradeoffAnalyticsExample.java +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,10 +40,10 @@ public static void main(String[] args) { | 40 | 40 | List<Column> columns = new ArrayList<Column>(); | 41 | 41 | problem.setColumns(columns); | 42 | 42 |
| 43 | | - columns.add(new NumericColumn().withRange(0, 100).withKey(price).withGoal(Goal.MIN) | 44 | | - .withObjective(true)); | 45 | | - columns.add(new NumericColumn().withKey(screen).withGoal(Goal.MAX).withObjective(true)); | 46 | | - columns.add(new NumericColumn().withKey(ram).withGoal(Goal.MAX)); | | 43 | + columns.add(new NumericColumn().range(0, 100).key(price).goal(Goal.MIN) | | 44 | + .objective(true)); | | 45 | + columns.add(new NumericColumn().key(screen).goal(Goal.MAX).objective(true)); | | 46 | + columns.add(new NumericColumn().key(ram).goal(Goal.MAX)); | 47 | 47 |
| 48 | 48 | // Define the options to choose | 49 | 49 | List<Option> options = new ArrayList<Option>(); | @@ -53,19 +53,19 @@ public static void main(String[] args) { | 53 | 53 | galaxySpecs.put(price, 50); | 54 | 54 | galaxySpecs.put(ram, 45); | 55 | 55 | galaxySpecs.put(screen, 5); | 56 | | - options.add(new Option("1", "Galaxy S4").withValues(galaxySpecs)); | | 56 | + options.add(new Option("1", "Galaxy S4").values(galaxySpecs)); | 57 | 57 |
| 58 | 58 | HashMap<String, Object> iphoneSpecs = new HashMap<String, Object>(); | 59 | 59 | iphoneSpecs.put(price, 99); | 60 | 60 | iphoneSpecs.put(ram, 40); | 61 | 61 | iphoneSpecs.put(screen, 4); | 62 | | - options.add(new Option("2", "iPhone 5").withValues(iphoneSpecs)); | | 62 | + options.add(new Option("2", "iPhone 5").values(iphoneSpecs)); | 63 | 63 |
| 64 | 64 | HashMap<String, Object> optimusSpecs = new HashMap<String, Object>(); | 65 | 65 | optimusSpecs.put(price, 10); | 66 | 66 | optimusSpecs.put(ram, 300); | 67 | 67 | optimusSpecs.put(screen, 5); | 68 | | - options.add(new Option("3", "LG Optimus G").withValues(optimusSpecs)); | | 68 | + options.add(new Option("3", "LG Optimus G").values(optimusSpecs)); | 69 | 69 |
| 70 | 70 | // Call the service and get the resolution | 71 | 71 | Dilemma dilemma = service.dilemmas(problem).execute(); | |
Collapse file Copy file name to clipboardExpand all lines: examples/retrieve-and-rank-solrj/pom.xml +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | <dependency> | 28 | 28 | <groupId>com.ibm.watson.developer_cloud</groupId> | 29 | 29 | <artifactId>java-sdk</artifactId> | 30 | | - <version>2.10.0</version> | | 30 | + <version>3.0.0</version> | 31 | 31 | </dependency> | 32 | 32 | </dependencies> | 33 | 33 | </project> |
|