org.apache.poi.util.TempFile Java Examples

The following examples show how to use org.apache.poi.util.TempFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OraBulkLoaderTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  transformMockHelper = new TransformMockHelper<OraBulkLoaderMeta, OraBulkLoaderData>( "TEST_CREATE_COMMANDLINE",
    OraBulkLoaderMeta.class, OraBulkLoaderData.class );
  when( transformMockHelper.logChannelFactory.create( any(), any( LoggingObjectInterface.class ) ) ).thenReturn(
    transformMockHelper.logChannelInterface );
  when( transformMockHelper.pipeline.isRunning() ).thenReturn( true );
  oraBulkLoader = spy( new OraBulkLoader( transformMockHelper.transformMeta, transformMockHelper.iTransformData, 0,
    transformMockHelper.pipelineMeta, transformMockHelper.pipeline ) );

  tempControlFile = TempFile.createTempFile( "control", "test" );
  tempControlFile.deleteOnExit();
  tempDataFile = TempFile.createTempFile( "data", "test" );
  tempDataFile.deleteOnExit();
  tempControlFilepath = tempControlFile.getAbsolutePath();
  tempDataFilepath = tempDataFile.getAbsolutePath();
  tempControlVfsFilepath = "file:///" + tempControlFilepath;
  tempDataVfsFilepath = "file:///" + tempDataFilepath;
}
 
Example #2
Source File: OraBulkDataOutputTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpen() {
  try {
    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( variables ).environmentSubstitute( dataFileVfsPath );
    doReturn( tempFileObject ).when( oraBulkDataOutput ).getFileObject( tempFilePath, variables );
    doReturn( tempFilePath ).when( oraBulkDataOutput ).getFilename( tempFileObject );

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

  } catch ( Exception ex ) {
    fail( "If any exception occurs, this test fails: " + ex );
  }
}
 
Example #3
Source File: EncryptedTempData.java    From hadoopoffice with Apache License 2.0 6 votes vote down vote up
public EncryptedTempData(CipherAlgorithm ca, ChainingMode cm) throws IOException {
	// generate random key for temnporary files
	if (ca!=null) {
				SecureRandom sr = new SecureRandom();
				byte[] iv = new byte[ca.blockSize];
				byte[] key = new byte[ca.defaultKeySize/8];
				sr.nextBytes(iv);
				sr.nextBytes(key);
				SecretKeySpec skeySpec = new SecretKeySpec(key,ca.jceId);
				this.ca = ca;
				this.cm = cm;
				if (this.cm.jceId.equals(ChainingMode.ecb.jceId)) { // does not work with Crpyto Functions since it does not require IV
					this.cm=ChainingMode.cbc;
				}
				this.ciEncrypt=CryptoFunctions.getCipher(skeySpec, ca, cm, iv, Cipher.ENCRYPT_MODE,"PKCS5Padding");
				this.ciDecrypt=CryptoFunctions.getCipher(skeySpec, ca, cm, iv, Cipher.DECRYPT_MODE,"PKCS5Padding");
	}
			this.tempFile=TempFile.createTempFile("hadooffice-poi-temp-data",".tmp");
}
 
Example #4
Source File: OraBulkLoaderTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@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();
  tempDataFile = TempFile.createTempFile( "data", "test" );
  tempDataFile.deleteOnExit();
  tempControlFilepath = tempControlFile.getAbsolutePath();
  tempDataFilepath = tempDataFile.getAbsolutePath();
  tempControlVfsFilepath = "file:///" + tempControlFilepath;
  tempDataVfsFilepath = "file:///" + tempDataFilepath;
}
 
Example #5
Source File: OraBulkDataOutputTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpen() {
  try {
    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 );
  }
}
 
Example #6
Source File: ChunkedCipherOutputStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) throws IOException, GeneralSecurityException {
    super(null);
    this.chunkSize = chunkSize;
    int cs = chunkSize == STREAMING ? 4096 : chunkSize;
    this.chunk = new byte[cs];
    this.plainByteFlags = new BitSet(cs);
    this.chunkBits = Integer.bitCount(cs-1);
    this.fileOut = TempFile.createTempFile("encrypted_package", "crypt");
    this.fileOut.deleteOnExit();
    this.out = new FileOutputStream(fileOut);
    this.dir = dir;
    this.cipher = initCipherForBlock(null, 0, false);
}
 
Example #7
Source File: EncryptedCachedDiskStringsTable.java    From hadoopoffice with Apache License 2.0 5 votes vote down vote up
/***
 * Create a new encrypted cached string table
 * 
 * @param part             package part with Shared String Table
 * @param cacheSize        cache = -1 means all is in memory, cache = 0 means
 *                         nothing is in memory, positive means only that
 *                         fractions is kept in-memory
 * @param compressTempFile true, if temporary file storage for shared string
 *                         table should be gzip compressed, false if not
 * @param                  ca, cipher algorithm leave it null for disabling
 *                         encryption (not recommended if source document is
 *                         encrypted)
 * @param                  cm, chaining mode, only need to be specified if
 *                         cipher algorithm is specified
 * @throws IOException
 */

public EncryptedCachedDiskStringsTable(PackagePart part, int cacheSize, boolean compressTempFile,
		CipherAlgorithm ca, ChainingMode cm) throws IOException {
	this.cacheSize = cacheSize;
	this.count=0;
	if (this.cacheSize > 0) {

		this.cache = new LRUCache<>(((int) Math.ceil(this.cacheSize / 0.75)) + 1); // based on recommendations of
																					// the Javadoc of HashMap
		this.stringPositionInFileList = new ArrayList<>(this.cacheSize);
	} else {
		this.cache = new LRUCache<>();
		this.stringPositionInFileList = new ArrayList<>();
	}
	this.stringPositionInFileList = new ArrayList<>();
	this.compressTempFile = compressTempFile;
	this.tempFile = TempFile.createTempFile("hadooffice-poi-temp-sst", ".tmp");
	this.tempFileSize = 0L;
	// generate random key for temnporary files
	if (ca != null) {
		SecureRandom sr = new SecureRandom();
		byte[] iv = new byte[ca.blockSize];
		byte[] key = new byte[ca.defaultKeySize / 8];
		sr.nextBytes(iv);
		sr.nextBytes(key);
		SecretKeySpec skeySpec = new SecretKeySpec(key, ca.jceId);
		this.ca = ca;
		this.cm = cm;
		if (this.cm.jceId.equals(ChainingMode.ecb.jceId)) { // does not work with Crpyto Functions since it does not require IV
			this.cm=ChainingMode.cbc;
		}
		this.ciEncrypt = CryptoFunctions.getCipher(skeySpec, this.ca, this.cm, iv, Cipher.ENCRYPT_MODE, "PKCS5Padding");
		this.ciDecrypt = CryptoFunctions.getCipher(skeySpec, this.ca, this.cm, iv, Cipher.DECRYPT_MODE, "PKCS5Padding");
	}
	this.originalIS = part.getInputStream();
	this.readFrom(this.originalIS);
}
 
Example #8
Source File: MSExcelOOXMLSignUtil.java    From hadoopoffice with Apache License 2.0 5 votes vote down vote up
public MSExcelOOXMLSignUtil(OutputStream finalOutputStream) throws IOException {
	this.finalOutputStream=finalOutputStream;
	LOG.info("Creating tempfile for signing");
	// create temporary outoputfile
	this.tempSignFile=TempFile.createTempFile("hadooffice-poi-temp-data-sign",".tmp");
	this.tempSignFileOS=new FileOutputStream(this.tempSignFile);
}
 
Example #9
Source File: FileUtils.java    From easyexcel with Apache License 2.0 4 votes vote down vote up
public static void createPoiFilesDirectory() {
    File poiFilesPathFile = new File(poiFilesPath);
    createDirectory(poiFilesPathFile);
    TempFile.setTempFileCreationStrategy(new DefaultTempFileCreationStrategy(poiFilesPathFile));
    poiFilesPathFile.deleteOnExit();
}
 
Example #10
Source File: StandardEncryptor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected StandardCipherOutputStream(DirectoryNode dir) throws IOException {
    this(dir, TempFile.createTempFile("encrypted_package", "crypt"));
}