List of usage examples for java.net URLConnection getRequestProperty
public String getRequestProperty(String key)
From source file:fr.free.divde.webcam.WebcamApplet.java
public void sendImage(JSObject parameters) { final String url = (String) parameters.getMember("url"); final String format = (String) getJSProperty(parameters, "format", "png"); final Map<String, Object> headers = getJSMapProperty(parameters, "headers"); final JSObject callback = (JSObject) getJSProperty(parameters, "callback", null); imageCapture.captureImage(new ImageListener() { @Override/*from ww w. j a v a2 s . c o m*/ public void nextFrame(BufferedImage image) { try { URL urlObject = new URL(getDocumentBase(), url); URLConnection connection = urlObject.openConnection(); connection.setDoOutput(true); setHeaders(connection, headers); if (connection.getRequestProperty("content-type") == null) { // default content type connection.setRequestProperty("content-type", "image/" + format); } OutputStream out = connection.getOutputStream(); ImageIO.write(image, format, out); out.flush(); out.close(); if (callback != null) { StringWriter response = new StringWriter(); IOUtils.copy(connection.getInputStream(), response, "UTF-8"); callJS(callback, response.toString()); } } catch (Exception e) { e.printStackTrace(); } } }); }