<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Narendra Kumar</title>
    <description>The latest articles on DEV Community by Narendra Kumar (@narendraomshiv).</description>
    <link>https://dev.to/narendraomshiv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F878646%2Ff8dbc430-1bc6-42a8-b39c-69a43f874716.jpeg</url>
      <title>DEV Community: Narendra Kumar</title>
      <link>https://dev.to/narendraomshiv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/narendraomshiv"/>
    <language>en</language>
    <item>
      <title>HTTP Server unable to handle Mac OS, Linux print request</title>
      <dc:creator>Narendra Kumar</dc:creator>
      <pubDate>Fri, 17 Jun 2022 12:07:52 +0000</pubDate>
      <link>https://dev.to/narendraomshiv/http-server-unable-to-handle-mac-os-linux-print-request-53d6</link>
      <guid>https://dev.to/narendraomshiv/http-server-unable-to-handle-mac-os-linux-print-request-53d6</guid>
      <description>&lt;p&gt;public HttpIppServerTransport(String path, int port) throws IOException {&lt;br&gt;
        server = HttpServer.create(new InetSocketAddress(port), 0);&lt;br&gt;
        server.createContext(path, new IppHandler());&lt;br&gt;
        server.setExecutor(null);&lt;br&gt;
        server.start();&lt;br&gt;
    }&lt;/p&gt;

&lt;p&gt;private class IppHandler implements HttpHandler {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    @Override
    public void handle(HttpExchange exchange) throws IOException {

            Headers requestHeaders = exchange.getRequestHeaders();
            //User-agent
            String useragent = requestHeaders.getFirst("User-agent");

        //  int contentLength = Integer.parseInt(requestHeaders.getFirst("Content-length"));

            //System.out.println("contentLength :" + contentLength);

            if (exchange.getRequestMethod().equalsIgnoreCase("POST")) {
                try {
                    OutputStream os = exchange.getResponseBody();

                     Map parameters =(Map)exchange.getAttribute("parameters");

                    System.out.println("parameters"+parameters);


                    InputStream is = exchange.getRequestBody();
                    System.out.println("++++++++++++++++++++++++++++++++++++++++");
                    byte[] inputstreamdata=is.readAllBytes();

                    System.out.println("inputstreamdata "+inputstreamdata.length+" bytes");

                    //Writing utf8 in file
                    File file = new File("C:\\Users\\admin\\Desktop\\mydoc.txt");
                    OutputStreamWriter datafile = new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8");
                    BufferedWriter buffwriter = new BufferedWriter(datafile);// Writing the data with

                    if(inputstreamdata.length&amp;gt;0) {
                     for (int i=0;i&amp;lt;inputstreamdata.length;i++)
                        {

                         byte mybyte=inputstreamdata[i];

                           // System.out.println("byte to binary"+Integer.toBinaryString(mybyte));                             // 1111 1110

                            String resultWithPadZero = String.format("%12s", Integer.toBinaryString(mybyte)).replace(" ", "0");
                            //String resultWithPadZero = String.format(Integer.toBinaryString(mybyte));
                            //System.out.println(resultWithPadZero);  // 00000000000000000000000011111110

                           // System.out.println(printBinary(resultWithPadZero, 8, "|"));  

                            //Writing utf8 data in file
                            buffwriter.write(inputstreamdata[i]);
                            buffwriter.flush();



                         //System.out.println(inputstreamdata[i]);
                        }
                    System.out.println("POSTMETHOD***data written successfully");
                     buffwriter.close();
                    // String response = "Invalid shutdown key\n";
                     //exchange.sendResponseHeaders(HTTP_OK, response.getBytes().length);
                     //exchange.getResponseBody().write(response.getBytes());

                     byte test = (byte) 0x012;

                     //exchange.sendResponseHeaders(test, 0);// Idle - Invalid printer command "Clean".

                    exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);


                     System.out.println("after sendResponseHeaders response code is : "+exchange.getResponseCode());
                    }

                } catch (NumberFormatException | IOException e) {
                }

            } 

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
  </channel>
</rss>
