/** * writes a representation of the QR code to the supplied {@link OutputStream} * * @param stream the {@link OutputStream} to write QR Code to */ public void writeTo(OutputStream stream) { try { writeToStream(stream); } catch (Exception e) { throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e); } }
/** * returns a {@link ByteArrayOutputStream} representation of the QR code * * @return qrcode as stream */ public ByteArrayOutputStream stream() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { writeToStream(stream); } catch (Exception e) { throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e); } return stream; }
/** * returns a {@link File} representation of the QR code. The file is set to be deleted on exit (i.e. {@link * java.io.File#deleteOnExit()}). If you want the file to live beyond the life of the jvm process, you should make a copy. * * @return qrcode as file */ public File file() { File file; try { file = createTempFile(); MatrixToImageWriter.writeToPath(createMatrix(), imageType.toString(), file.toPath()); } catch (Exception e) { throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e); } return file; }
/** * returns a {@link File} representation of the QR code. The file has the given name. The file is set to be deleted on exit * (i.e. {@link java.io.File#deleteOnExit()}). If you want the file to live beyond the life of the jvm process, you should * make a copy. * * @param name name of the created file * @return qrcode as file * @see #file() */ public File file(String name) { File file; try { file = createTempFile(name); MatrixToImageWriter.writeToPath(createMatrix(), imageType.toString(), file.toPath()); } catch (Exception e) { throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e); } return file; }