How to use MatrixToImageWriter.writeToStream() from javase in a server app

2,536 views
Skip to first unread message

George Vodarek

unread,
Jun 27, 2013, 8:40:43 PM6/27/13
to zx...@googlegroups.com
I'm writing a web app to display a QR-code.   Here is the code:

BitMatrix bits = new QRCodeWriter().encode(otpURI, BarcodeFormat.QR_CODE, 200, 200);
ByteArrayOutputStream out = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bits, "PNG", out);
String qrCodeString = new Base64().encodeToString(out.toByteArray());

The first line creates a BitMatrix of the QR-code image.  The third line writes the bits to a stream so I can display it.  This works, BUT the writeToStream() call appears to launch a new Java App on my Mac, which is weird and undesirable.  It looks like this call launches a new process somehow, because when I quit that app it kills the original process.

What is the purpose of the javase.jar?  Perhaps I shouldn't be using it on the server?  Is there an alternative MatrixToImageWriter class elsewhere?

George.

Sean Owen

unread,
Jun 30, 2013, 5:52:53 AM6/30/13
to zx...@googlegroups.com
You're creating a new java process by running your program. That's what you see on OS X. Nothing here spawns a new process, no. javase.jar is just a jar full of the code you are calling. You can use it anywhere.

Lachezar Dobrev

unread,
Jul 1, 2013, 10:02:55 AM7/1/13
to George Vodarek, zx...@googlegroups.com
Try starting the 'server' with -Djava.awt.headless=true

2013/6/28 George Vodarek <gvod...@pingidentity.com>:

George Vodarek

unread,
Jul 4, 2013, 1:13:40 PM7/4/13
to Lachezar Dobrev, zx...@googlegroups.com
Thanks, Lachezar.  I'll try that.  The thing is I'm running a web app on the Jetty server started it from the command line.  The other thing is that this only appears to happen on a Mac.  In Windows and Linux I don't see that new app start up.  Strange.

George.
--
George Vodarek  |  Sr. Response Engineer
PingIdentity  |   www.pingidentity.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
O: +1 604.697.6977   
Email: gvod...@pingidentity.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Connect with Ping
Twitter: @pingidentity
LinkedIn Group: Ping's Identity Cloud    
Facebook.com/pingidentitypage

Sean Owen

unread,
Jul 4, 2013, 2:22:21 PM7/4/13
to zx...@googlegroups.com
Do you really mean your Java based web app starts a whole new Java process? That's completely unnecessary.

But if you do that it is starting a new process on every platform. Its just that OS X puts an icon on it.

Reply all
Reply to author
Forward
0 new messages