11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
3-
3+ // <imports>
44import org .apache .http .HttpEntity ;
55import org .apache .http .client .methods .CloseableHttpResponse ;
6- import org .apache .http .client .methods .HttpPost ;
6+ import org .apache .http .client .methods .HttpPut ;
77import org .apache .http .entity .StringEntity ;
88import org .apache .http .impl .client .CloseableHttpClient ;
99import org .apache .http .impl .client .HttpClients ;
1010import org .apache .http .util .EntityUtils ;
1111import java .io .IOException ;
1212import java .nio .file .Files ;
1313import java .nio .file .Paths ;
14+ // </imports>
1415
1516public class RecognizeInk {
16-
17+ // <vars>
1718 // Add your Azure Ink Recognition subscription key to your environment variables.
1819 private static final String subscriptionKey = System .getenv ("INK_RECOGNITION_SUBSCRIPTION_KEY" );
1920
@@ -22,23 +23,26 @@ public class RecognizeInk {
2223 public static final String inkRecognitionUrl = "/inkrecognizer/v1.0-preview/recognize" ;
2324 // Replace the dataPath string with a path to the JSON formatted ink stroke data file.
2425 private static final String dataPath = "PATH_TO_INK_STROKE_DATA" ;
25-
26+ // </vars>
27+ // <main>
2628 public static void main (String [] args ) throws Exception {
2729
2830 String requestData = new String (Files .readAllBytes (Paths .get (dataPath )), "utf-8" );
2931 recognizeInk (requestData );
3032 }
31-
33+ // </main>
34+ // <recognizeInk>
3235 static void recognizeInk (String requestData ) {
3336 System .out .println ("Sending an Ink recognition request." );
3437
3538 String result = sendRequest (rootUrl , inkRecognitionUrl , subscriptionKey , requestData );
3639 System .out .println (result );
3740 }
38-
41+ // </recognizeInk>
42+ // <sendRequest>
3943 static String sendRequest (String endpoint , String apiAddress , String subscriptionKey , String requestData ) {
4044 try (CloseableHttpClient client = HttpClients .createDefault ()) {
41- HttpPost request = new HttpPost (endpoint + apiAddress );
45+ HttpPut request = new HttpPut (endpoint + apiAddress );
4246 // Request headers.
4347 request .setHeader ("Content-Type" , "application/json" );
4448 request .setHeader ("Ocp-Apim-Subscription-Key" , subscriptionKey );
@@ -57,4 +61,5 @@ static String sendRequest(String endpoint, String apiAddress, String subscriptio
5761 }
5862 return null ;
5963 }
64+ // </sendRequest>
6065}
0 commit comments