Example usage for org.apache.commons.io IOUtils copyLarge

List of usage examples for org.apache.commons.io IOUtils copyLarge

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils copyLarge.

Prototype

public static long copyLarge(Reader input, Writer output) throws IOException 

Source Link

Document

Copy chars from a large (over 2GB) Reader to a Writer.

Usage

From source file:net.awl.edoc.pdfa.font.CFFTest.java

/**
 * @param args/*  w w  w.j ava2s. co m*/
 */
public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream("/home/eric/UneCFFType0.cff0");
    // FileInputStream fis = new FileInputStream("/home/eric/UneCFFType2.cff2");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IOUtils.copyLarge(fis, bos);

    CFFParser cp = new CFFParser();
    List<CFFFont> lf = cp.parse(bos.toByteArray());

    CFFFontROS font = (CFFFontROS) lf.get(0);
    System.out.println("CharstringType : " + font.getProperty("CharstringType"));

    int CID = 85;
    int fdAIndex = font.getFdSelect().getFd(CID);
    Map<String, Object> fd = font.getFontDict().get(fdAIndex);
    Map<String, Object> pd = font.getPrivDict().get(fdAIndex);
    for (Mapping m : font.getMappings()) {
        if (m.getSID() == CID) {
            // List<Object> l1 = new
            // Type1CharStringParser().parse(font.getCharStringsDict().get(m.getName()));
            List<Object> l2 = new Type2CharStringParser().parse(m.getBytes());
            System.err.println("");
        }
    }
    System.out.println("");
}

From source file:com.intel.cosbench.api.mock.MockUtils.java

public static void consume(InputStream data) {
    try {//from  ww w . j  a  va2s  .c o m
        IOUtils.copyLarge(data, new NullOutputStream());
    } catch (IOException ioe) {
        // will not happen
    }
}

From source file:com.github.lucapino.sheetmaker.PreviewJFrame.java

public static void main(String[] args) {
    System.setProperty("awt.useSystemAAFontSettings", "on");
    System.setProperty("swing.aatext", "true");
    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from ww w.java2s  . c  om*/
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                File tmpFolder = new File("/tmp/images");
                tmpFolder.mkdir();

                String coverPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/cover.jpg";
                String backdropPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/backdrop.jpg";
                String fanart1Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart1.jpg";
                String fanart2Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart2.jpg";
                String fanart3Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart3.jpg";

                PreviewJFrame frame = new PreviewJFrame();
                logger.info("Creating parser...");
                InfoRetriever parser = new MediaInfoRetriever();
                MovieInfo movieInfo = parser.getMovieInfo("/media/tagliani/Elements/Film/JackRyan.mkv");
                logger.info("Retrieving movie file info...");
                logger.info("Creating dataretriever...");
                DataRetriever retriever = new DataRetrieverImpl();
                logger.info("Retrieving movie data...");
                Movie movie = retriever.retrieveMovieFromImdbID("tt1205537", "IT");
                logger.info("Retrieving backdrops and fanart...");
                List<Artwork> images = movie.getBackdrops();
                // background
                logger.info("Saving backdrop...");
                IOUtils.copyLarge(new URL(images.get(0).getImageURL()).openStream(),
                        new FileOutputStream(backdropPath));
                for (int i = 1; i < 4; i++) {
                    // fanart1
                    // fanart2
                    // fanart3
                    String imageURL = images.get(i).getImageURL();
                    logger.info("Saving fanart{}...", i);
                    IOUtils.copyLarge(new URL(imageURL).openStream(),
                            new FileOutputStream(tmpFolder.getAbsolutePath() + "/fanart" + i + ".jpg"));
                }
                // cover
                logger.info("Retrieving cover...");
                Artwork cover = movie.getPosters().get(0);
                String imageURL = cover.getImageURL();
                logger.info("Saving cover...");
                IOUtils.copyLarge(new URL(imageURL).openStream(), new FileOutputStream(coverPath));

                Map<String, String> tokenMap = TemplateFilter.createTokenMap(movie, movieInfo, null);

                logger.info("Creating renderer...");
                JavaTemplateRenderer renderer = new JavaTemplateRenderer();
                JPanel imagePanel = null;
                try {
                    logger.info("Rendering image...");
                    imagePanel = renderer.renderTemplate(
                            this.getClass().getResource("/templates/simplicity/template.xml"), tokenMap,
                            backdropPath, fanart1Path, fanart2Path, fanart3Path, coverPath);
                    logger.info("Adding image to frame...");
                    frame.add(imagePanel);

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                imagePanel.setPreferredSize(new Dimension(imagePanel.getWidth(), imagePanel.getHeight()));
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                frame.setVisible(true);
                frame.pack();
                logger.info("Creating image for save...");
                BufferedImage imageTosave = ScreenImage.createImage(imagePanel);
                logger.info("Saving image...");
                ScreenImage.writeImage(imageTosave, "/tmp/images/final.png");
                logger.info("Image saved...");
            } catch (Exception ex) {
                logger.error("Error: ", ex);
            }
        }

    });

}

From source file:herddb.upgrade.ZIPUtils.java

public static void createZipWithOneEntry(String entryfilename, InputStream filedata, OutputStream out,
        Charset fileNamesCharset) throws IOException {
    try (ZipOutputStream zipper = new ZipOutputStream(out, fileNamesCharset);) {
        int posslash = entryfilename.indexOf('/');
        if (posslash >= 0) { // gestione caso semplice di directory singola es. META-INF/magnews-app.xml per i test di MN
            String dire = entryfilename.substring(0, posslash);
            ZipEntry entry = new ZipEntry(dire);
            zipper.putNextEntry(entry);/*from w w w  .j  ava 2 s. co m*/
            zipper.closeEntry();
        }
        ZipEntry entry = new ZipEntry(entryfilename);
        zipper.putNextEntry(entry);
        IOUtils.copyLarge(filedata, zipper);
        zipper.closeEntry();
    }
}

From source file:com.google.code.docbook4j.BaseDocbook4JTest.java

protected void writeToFile(InputStream in, String filename) throws Throwable {

    File targetDir = new File("target/testout/" + getTargetFolder());
    targetDir.mkdirs();/*from   ww  w .  j ava  2 s  .co m*/

    FileOutputStream out = new FileOutputStream(new File(targetDir, filename));
    long count = IOUtils.copyLarge(in, out);
    Assert.assertTrue(count > 0);
    log.info("bytes copied: {} ", count);
    out.close();
    in.close();
}

From source file:eu.freme.eservices.epublishing.Unzipper.java

public static void unzip(ZipInputStream zis, File outputFolder) throws IOException {
    //create output directory is not exists

    if (!outputFolder.exists() && !outputFolder.mkdirs()) {
        throw new IOException("Cannot create directory " + outputFolder);
    }/*  w  w  w.j a  va 2s . c  om*/

    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {
        String fileName = ze.getName();
        File newFile = new File(outputFolder, fileName);

        logger.debug("file unzip : " + newFile.getAbsoluteFile());

        //create all non exists folders
        //else you will hit FileNotFoundException for compressed folder
        File parentDir = newFile.getParentFile();
        if (!parentDir.exists() && !parentDir.mkdirs()) {
            throw new IOException("Cannot create directory " + newFile.getParent());
        }

        if (ze.isDirectory()) {
            newFile.mkdirs();
        } else {
            try (FileOutputStream fos = new FileOutputStream(newFile)) {
                IOUtils.copyLarge(zis, fos);
            }
        }
        ze = zis.getNextEntry();
    }
    zis.closeEntry();
}

From source file:net.padaf.preflight.font.type1.PeekInputStream.java

public PeekInputStream(InputStream source) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {/*  w  w  w.j av a  2s . c o m*/
        IOUtils.copyLarge(source, bos);
        content = bos.toByteArray();
    } finally {
        IOUtils.closeQuietly(source);
        IOUtils.closeQuietly(bos);
    }
}

From source file:com.nuvolect.securesuite.util.OmniZip.java

public static boolean zipFiles(Context ctx, Iterable<OmniFile> files, OmniFile zipOmni, int destination) {

    ZipOutputStream zos = null;/*  w  w w.  j a  va  2s  .co m*/
    LogUtil.log(LogUtil.LogType.OMNI_ZIP, "ZIPPING TO: " + zipOmni.getPath());

    try {
        zos = new ZipOutputStream(zipOmni.getOutputStream());

        for (OmniFile file : files) {

            if (file.isDirectory()) {

                zipSubDirectory(ctx, "", file, zos);
            } else {

                LogUtil.log(LogUtil.LogType.OMNI_ZIP,
                        "zipping up: " + file.getPath() + " (bytes: " + file.length() + ")");

                /**
                 * Might get lucky here, can it associate the name with the copyLarge that follows
                 */
                ZipEntry ze = new ZipEntry(file.getName());
                zos.putNextEntry(ze);

                IOUtils.copyLarge(file.getFileInputStream(), zos);

                zos.flush();
            }
        }

        zos.close();
        return true;
    } catch (IOException e) {
        LogUtil.logException(LogUtil.LogType.OMNI_ZIP, e);
        e.printStackTrace();
    }

    return false;
}

From source file:net.padaf.preflight.util.ByteArrayDataSource.java

public ByteArrayDataSource(InputStream is) throws IOException {
    data = new ByteArrayOutputStream();
    IOUtils.copyLarge(is, data);
    IOUtils.closeQuietly(is);
}

From source file:com.hs.mail.util.FileUtils.java

public static void compress(File srcFile, File destFile) throws IOException {
    InputStream input = null;/*  ww  w.j a v a2 s  .c o m*/
    OutputStream output = null;
    try {
        input = new BufferedInputStream(new FileInputStream(srcFile));
        output = new GZIPOutputStream(new FileOutputStream(destFile));
        IOUtils.copyLarge(input, output);
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(input);
    }
}