Example usage for org.apache.poi.util TempFile createTempFile

List of usage examples for org.apache.poi.util TempFile createTempFile

Introduction

In this page you can find the example usage for org.apache.poi.util TempFile createTempFile.

Prototype

public static File createTempFile(String prefix, String suffix) throws IOException 

Source Link

Document

Creates a new and empty temporary file.

Usage

From source file:com.axelor.studio.service.template.StudioTemplateService.java

License:Open Source License

public MetaFile export(String templateName) throws IOException {

    List<String> models = new ArrayList<String>();
    models.add("MetaSelect,self.name in (select metaSelect.name from MetaField where customised = true)");
    models.add("MetaModel,customised = true");
    models.add("RightManagement");
    models.add("ViewBuilder,viewType != 'dashboard'");
    models.add("ViewBuilder,viewType = 'dashboard'");
    models.add("MenuBuilder");
    models.add("Wkf");
    models.add("ReportBuilder");
    models.add("ActionBuilder");
    models.add("Template");

    File file = TempFile.createTempFile("template", ".xml");
    xmlCreator.createXml(models, file);/*  www  .j a v  a 2  s.co  m*/

    return createMetaZip(templateName, file);

}

From source file:com.github.poi.AesZipFileZipEntrySource.java

License:Apache License

public static AesZipFileZipEntrySource createZipEntrySource(InputStream is)
        throws IOException, GeneralSecurityException {
    // generate session key
    SecureRandom sr = new SecureRandom();
    byte[] ivBytes = new byte[16], keyBytes = new byte[16];
    sr.nextBytes(ivBytes);/*from  w  w w.j  av a2  s. co  m*/
    sr.nextBytes(keyBytes);
    final File tmpFile = TempFile.createTempFile("protectedXlsx", ".zip");
    copyToFile(is, tmpFile, CipherAlgorithm.aes128, keyBytes, ivBytes);
    IOUtils.closeQuietly(is);
    return fileToSource(tmpFile, CipherAlgorithm.aes128, keyBytes, ivBytes);
}

From source file:org.pentaho.di.trans.steps.orabulkloader.OraBulkDataOutputTest.java

License:Apache License

@Test
public void testOpen() {
    try {//w w w .j  a v  a  2  s.  c  o m
        File tempFile = TempFile.createTempFile("temp", "test");
        String tempFilePath = tempFile.getAbsolutePath();
        String dataFileVfsPath = "file:///" + tempFilePath;
        LocalFile tempFileObject = mock(LocalFile.class);

        tempFile.deleteOnExit();

        doReturn(dataFileVfsPath).when(oraBulkLoaderMeta).getDataFile();
        doReturn(tempFilePath).when(space).environmentSubstitute(dataFileVfsPath);
        doReturn(tempFileObject).when(oraBulkDataOutput).getFileObject(tempFilePath, space);
        doReturn(tempFilePath).when(oraBulkDataOutput).getFilename(tempFileObject);

        oraBulkDataOutput.open(space, sqlldrProcess);
        oraBulkDataOutput.close();

    } catch (Exception ex) {
        fail("If any exception occurs, this test fails: " + ex);
    }
}

From source file:org.pentaho.di.trans.steps.orabulkloader.OraBulkLoaderTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    stepMockHelper = new StepMockHelper<OraBulkLoaderMeta, OraBulkLoaderData>("TEST_CREATE_COMMANDLINE",
            OraBulkLoaderMeta.class, OraBulkLoaderData.class);
    when(stepMockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class)))
            .thenReturn(stepMockHelper.logChannelInterface);
    when(stepMockHelper.trans.isRunning()).thenReturn(true);
    oraBulkLoader = spy(new OraBulkLoader(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0,
            stepMockHelper.transMeta, stepMockHelper.trans));

    tempControlFile = TempFile.createTempFile("control", "test");
    tempControlFile.deleteOnExit();/*from  w ww. j  a v  a  2 s .c o m*/
    tempDataFile = TempFile.createTempFile("data", "test");
    tempDataFile.deleteOnExit();
    tempControlFilepath = tempControlFile.getAbsolutePath();
    tempDataFilepath = tempDataFile.getAbsolutePath();
    tempControlVfsFilepath = "file:///" + tempControlFilepath;
    tempDataVfsFilepath = "file:///" + tempDataFilepath;
}

From source file:org.talend.repository.ui.wizards.metadata.connection.files.excel.ExcelReader.java

License:Open Source License

/**
 * <li><b>Background</b></li>: After update the poi-ooxml jar from poi-ooxml-3.9 to poi-ooxml-3.11, this api
 * "PackageHelper.createTempFile()" is removed. so need to resolve this compile problem in our codes where calling
 * this api; And I find this function is only used to create a temp file, so I just copy the original source to here <br>
 * <li><b>other information</b></li>: The following function source is copied from the source code of
 * org.apache.poi.util.PackageHelper.createTempFile() <source version: 3.10.1><br>
 * The source can be found from:/*w w w  .j av  a 2 s  .com*/
 * http://grepcode.com/file/repo1.maven.org/maven2/org.apache.poi/poi-ooxml/3.10.1/org/apache/poi/util/
 * PackageHelper.java?av=f <br>
 * The useage of "PackageHelper.createTempFile()" in our codes is added from TDI-24490
 * 
 * @return
 * @throws IOException
 */
private File createTempFile() throws IOException {
    File file = TempFile.createTempFile("poi-ooxml-", ".tmp"); //$NON-NLS-1$ //$NON-NLS-2$
    // there is no way to pass an existing file to Package.create(file),
    // delete first, the file will be re-created in Packe.create(file)
    file.delete();
    return file;

}

From source file:poi.hpsf.examples.CopyCompare.java

License:Apache License

/**
 * <p>Runs the example program. The application expects one or two
 * arguments:</p>// w  ww  .  j  a  v a2  s .  c om
 * 
 * <ol>
 * 
 * <li><p>The first argument is the disk file name of the POI filesystem to
 * copy.</p></li>
 * 
 * <li><p>The second argument is optional. If it is given, it is the name of
 * a disk file the copy of the POI filesystem will be written to. If it is
 * not given, the copy will be written to a temporary file which will be
 * deleted at the end of the program.</p></li>
 * 
 * </ol>
 *
 * @param args Command-line arguments.
 * @exception MarkUnsupportedException if a POI document stream does not
 * support the mark() operation.
 * @exception NoPropertySetStreamException if the application tries to
 * create a property set from a POI document stream that is not a property
 * set stream.
 * @exception java.io.IOException if any I/O exception occurs.
 * @exception java.io.UnsupportedEncodingException if a character encoding is not
 * supported.
 */
public static void main(final String[] args) throws NoPropertySetStreamException, MarkUnsupportedException,
        UnsupportedEncodingException, IOException {
    String originalFileName = null;
    String copyFileName = null;

    /* Check the command-line arguments. */
    if (args.length == 1) {
        originalFileName = args[0];
        File f = TempFile.createTempFile("CopyOfPOIFileSystem-", ".ole2");
        f.deleteOnExit();
        copyFileName = f.getAbsolutePath();
    } else if (args.length == 2) {
        originalFileName = args[0];
        copyFileName = args[1];
    } else {
        System.err.println("Usage: " + CopyCompare.class.getName() + "originPOIFS [copyPOIFS]");
        System.exit(1);
    }

    /* Read the origin POIFS using the eventing API. The real work is done
     * in the class CopyFile which is registered here as a POIFSReader. */
    final POIFSReader r = new POIFSReader();
    final CopyFile cf = new CopyFile(copyFileName);
    r.registerListener(cf);
    r.read(new FileInputStream(originalFileName));

    /* Write the new POIFS to disk. */
    cf.close();

    /* Read all documents from the original POI file system and compare them
     * with the equivalent document from the copy. */
    final POIFSFileSystem opfs = new POIFSFileSystem(new FileInputStream(originalFileName));
    final POIFSFileSystem cpfs = new POIFSFileSystem(new FileInputStream(copyFileName));

    final DirectoryEntry oRoot = opfs.getRoot();
    final DirectoryEntry cRoot = cpfs.getRoot();
    final StringBuffer messages = new StringBuffer();
    if (equal(oRoot, cRoot, messages))
        System.out.println("Equal");
    else
        System.out.println("Not equal: " + messages.toString());
}