title: Correct way to send escape codes (raw data) to printer
body: <p>In the context of a bigger application, my applet needs to print some data to a Zebra or a Dymo (depending on what the user has installed) label printer.</p>
  
  <p>The data i receive is in an escaped form, data that i just need to send to the printer and let it interpret it.</p>
  
  <p>Searching i've found two solutions.
  Method 1:</p>
  
  <pre><code>byte[] printdata;
  PrintService pservice = PrintServiceLookup.lookupDefaultPrintService(); //or get the printer in some other way
  DocPrintJob job = pservice.createPrintJob();
  DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
  Doc doc = new SimpleDoc(printdata, flavor, null);
  </code></pre>
  
  <p>and method 2:</p>
  
  <pre><code>PrintStream printStream = new PrintStream(new FileOutputStream(“LPT1”));
  printStream.print(“Hello World”);
  printStream.close();
  </code></pre>
  
  <p>I need this to work cross-platform, with printers using the USB or the serial port.
  What is the <em>correct</em> way to implement this behaviour?</p>
  
  <p>One problem with method 2 is that i would need to find the URL of the printer in same way...</p>