Example usage for org.apache.poi.util IOUtils toByteArray

List of usage examples for org.apache.poi.util IOUtils toByteArray

Introduction

In this page you can find the example usage for org.apache.poi.util IOUtils toByteArray.

Prototype

public static byte[] toByteArray(InputStream stream) throws IOException 

Source Link

Document

Reads all the data from the input stream, and returns the bytes read.

Usage

From source file:AddAudioToPptx.java

License:Apache License

public static void main(String[] args) throws Exception {
    URL video = new URL("http://archive.org/download/test-mpeg/test-mpeg.mpg");
    // URL video = new URL("file:test-mpeg.mpg");

    XMLSlideShow pptx = new XMLSlideShow();

    // add video file
    String videoFileName = "lego_edsheeran.mp3";
    PackagePartName partName = PackagingURIHelper.createPartName("/ppt/media/" + videoFileName);
    PackagePart part = pptx.getPackage().createPart(partName, "audio/mpeg");
    OutputStream partOs = part.getOutputStream();
    //InputStream fis = video.openStream();
    FileInputStream fis = new FileInputStream(videoFileName);
    byte buf[] = new byte[1024];
    for (int readBytes; (readBytes = fis.read(buf)) != -1; partOs.write(buf, 0, readBytes))
        ;/*from  www .ja  v a2s.  co m*/
    fis.close();
    partOs.close();

    XSLFSlide slide1 = pptx.createSlide();

    byte[] picture = IOUtils.toByteArray(new FileInputStream("audio.png"));

    //adding the image to the presentation
    XSLFPictureData idx = pptx.addPicture(picture, XSLFPictureData.PictureType.PNG);

    //creating a slide with given picture on it
    XSLFPictureShape pv1 = slide1.createPicture(idx);

    //XSLFPictureShape pv1 = // addPreview(pptx, slide1, part, 5, 50, 80);
    addAudio(pptx, slide1, part, pv1, 5);
    addTimingInfo(slide1, pv1);
    //XSLFPictureShape pv2 = addPreview(pptx, slide1, part, 9, 50, 250);
    //addVideo(pptx, slide1, part, pv2, 9);
    //addTimingInfo(slide1, pv2);

    FileOutputStream fos = new FileOutputStream("pptx-with-audio.pptx");
    pptx.write(fos);
    fos.close();

    pptx.close();
}

From source file:acuario.controller.InsumoEdcController.java

@FXML
private void btnAcepta() {
    if (datosValidos()) {
        insumo.setInsumocodigo(insumoCodigo.getTexto());
        insumo.setInsumonombre(insumoNombre.getTexto());
        insumo.setInsumodescripcion(insumoDescripcion.getTexto());
        insumo.setInsumovalor(new BigDecimal(Double.parseDouble(insumoValor.getTexto())));
        if (file != null) {
            FileInputStream is = null;
            byte[] res = null;
            try {
                is = new FileInputStream(file.getAbsolutePath());
                res = IOUtils.toByteArray(is);
                insumo.setInsumofoto(res);
            } catch (FileNotFoundException ex) {
                System.err.println("FileNotFoundException:" + InsumoEdcController.class.getName() + " " + ex);
            } catch (IOException ex) {
                System.err.println("IOException:" + InsumoEdcController.class.getName() + " " + ex);
            }/* ww  w.  j av a  2  s. c  o  m*/
        }
        insumo.setInsumounmed(Util.stringSeleccionado(insumoUnMed));
        insumo.setInsumotipo(Util.stringSeleccionado(insumoTipo));
        insumo.setInsumopresentacion(Util.stringSeleccionado(insumoUnMed));
        insumo.setInsumoestado("PASIVO");
        grabaInsumoempresa(insumo);
        okClicked = true;
        dialogStage.close();
    }
}

From source file:acuario.controller.PersonaEdcController.java

@FXML
private void btnAcepta() {
    if (datosValidos()) {
        persona.setPersonarut(personaRUT.getTexto());
        persona.setPersonaapellidos(personaApellidos.getTexto());
        persona.setPersonanombres(personaNombres.getTexto());
        persona.setPersonacorreo(personaCorreo.getTexto());
        persona.setPersonadireccion(personaDireccion.getText());
        persona.setPersonafoto(null);//from w  w  w . j a v a2  s . c  o  m
        if (file != null) {
            FileInputStream is = null;
            byte[] res = null;
            try {
                is = new FileInputStream(file.getAbsolutePath());
                res = IOUtils.toByteArray(is);
                persona.setPersonafoto(res);
            } catch (FileNotFoundException ex) {
                System.err.println("FileNotFoundException:" + PersonaEdcController.class.getName() + " " + ex);
            } catch (IOException ex) {
                System.err.println("IOException:" + PersonaEdcController.class.getName() + " " + ex);
            }
        }
        persona.setPersonaciudad(Util.stringSeleccionado(personaCiudad));
        persona.setPersonacomuna(Util.stringSeleccionado(personaComuna));
        persona.setPersonamovil(personaMovil.getTexto());
        persona.setPersonatelefono(personaFijo.getTexto());
        persona.setPersonaestado("ACTIVO");
        okClicked = true;
        dialogStage.close();
    }
}

From source file:architecture.ee.web.attachment.DefaultImageManager.java

License:Apache License

public Image createImage(int objectType, long objectId, String name, String contentType,
        InputStream inputStream) {
    Date now = new Date();
    ImageImpl image = new ImageImpl();
    image.setCreationDate(now);//from  w w w . jav a 2 s  .co m
    image.setModifiedDate(now);
    image.setObjectType(objectType);
    image.setObjectId(objectId);
    image.setContentType(contentType);
    image.setName(name);
    image.setImageId(-1L);

    try {
        image.setSize(IOUtils.toByteArray(inputStream).length);
        image.setInputStream(inputStream);
    } catch (IOException e) {
        log.debug(e);
    }
    return image;
}

From source file:at.tugraz.sss.serv.SSPDFFromXHTMLImageEmbedder.java

License:Apache License

@Override
public ReplacedElement createReplacedElement(LayoutContext layoutContext, BlockBox blockBox,
        UserAgentCallback uac, int cssWidth, int cssHeight) {

    Element element = blockBox.getElement();

    if (element == null) {
        return null;
    }//w w  w  .j  av a  2  s .c  o  m

    String nodeName = element.getNodeName();
    String className = element.getAttribute("class");
    String src = element.getAttribute("src");

    if (!"img".equals(nodeName) || !className.contains("xmyImagex") || src == null) {

        return superFactory.createReplacedElement(layoutContext, blockBox, uac, cssWidth, cssHeight);
    }

    InputStream in = null;

    try {

        try {
            in = new FileInputStream(src);
        } catch (Exception error) {
            throw error;
        }

        final byte[] bytes = IOUtils.toByteArray(in);
        final Image image = Image.getInstance(bytes);
        final FSImage fsImage = new ITextFSImage(image);

        fsImage.scale(cssWidth, cssHeight);

        return new ITextImageElement(fsImage);
    } catch (Exception error) {

        return superFactory.createReplacedElement(layoutContext, blockBox, uac, cssWidth, cssHeight);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:at.tugraz.sss.serv.util.SSPDFFromXHTMLImageEmbedder.java

License:Apache License

@Override
public ReplacedElement createReplacedElement(LayoutContext layoutContext, BlockBox blockBox,
        UserAgentCallback uac, int cssWidth, int cssHeight) {

    Element element = blockBox.getElement();

    if (element == null) {
        return null;
    }//  w  ww .  j a  v a 2 s  .co m

    String nodeName = element.getNodeName();
    String className = element.getAttribute("class");
    String src = element.getAttribute("src");

    if (!"img".equals(nodeName) || !className.contains("xmyImagex") || src == null) {

        return superFactory.createReplacedElement(layoutContext, blockBox, uac, cssWidth, cssHeight);
    }

    InputStream in = null;

    try {

        try {
            in = new FileInputStream(src);
        } catch (Exception error) {
            throw error;
        }

        final byte[] bytes = IOUtils.toByteArray(in);
        final Image image = Image.getInstance(bytes);
        final FSImage fsImage = new ITextFSImage(image);

        fsImage.scale(cssWidth, cssHeight);

        return new ITextImageElement(fsImage);
    } catch (Exception error) {

        SSLogU.debug(error);

        return superFactory.createReplacedElement(layoutContext, blockBox, uac, cssWidth, cssHeight);

    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:br.com.nfsconsultoria.nfsuporte.bean.ClienteBean.java

public void FileUp(FileUploadEvent evento) {
    try {//from   w ww .  j  a v a2  s.c  o  m
        FacesMessage message = new FacesMessage("Contrato",
                evento.getFile().getFileName() + " carregado com sucesso");
        FacesContext.getCurrentInstance().addMessage(null, message);
        UploadedFile contrato = evento.getFile();
        byte[] arquivo = (IOUtils.toByteArray(contrato.getInputstream()));
        this.cliente.setContrato(arquivo);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:br.com.nfsconsultoria.nfsuporte.bean.ClienteBean.java

public void FileTopUp(FileUploadEvent evento) {
    try {/* w w  w  . j  av a2 s  .  c  o  m*/
        FacesMessage message = new FacesMessage("Topologia",
                evento.getFile().getFileName() + " carregado com sucesso");
        FacesContext.getCurrentInstance().addMessage(null, message);
        UploadedFile contrato = evento.getFile();
        byte[] arquivo = (IOUtils.toByteArray(contrato.getInputstream()));
        this.cliente.setTopologia(arquivo);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.fy.utils.xwpf.XWPFTestDataSamples.java

License:Apache License

public static byte[] getImage(String filename) throws IOException {
    InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(filename);
    byte[] result = IOUtils.toByteArray(is);
    return result;
}

From source file:com.gst.infrastructure.documentmanagement.data.ImageData.java

License:Apache License

public byte[] getContent() {
    try {//from   w ww .j  a va 2s.  c o m
        if (this.storageType.equals(StorageType.S3.getValue()) && this.inputStream != null) {
            return IOUtils.toByteArray(this.inputStream);
        } else if (this.storageType.equals(StorageType.FILE_SYSTEM.getValue()) && this.file != null) {
            final FileInputStream fileInputStream = new FileInputStream(this.file);
            return IOUtils.toByteArray(fileInputStream);
        }
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
    return null;
}