Java Code Examples for org.apache.commons.io.FileUtils.forceDeleteOnExit()

The following are Jave code examples for showing how to use forceDeleteOnExit() of the org.apache.commons.io.FileUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: flume-release-1.7.0   File: TestLog.java   View Source Code Vote up 6 votes
@Before
public void setup() throws IOException {
  transactionID = 0;
  checkpointDir = Files.createTempDir();
  FileUtils.forceDeleteOnExit(checkpointDir);
  Assert.assertTrue(checkpointDir.isDirectory());
  dataDirs = new File[3];
  for (int i = 0; i < dataDirs.length; i++) {
    dataDirs[i] = Files.createTempDir();
    Assert.assertTrue(dataDirs[i].isDirectory());
  }
  log = new Log.Builder().setCheckpointInterval(1L)
                         .setMaxFileSize(MAX_FILE_SIZE)
                         .setQueueSize(CAPACITY)
                         .setCheckpointDir(checkpointDir)
                         .setLogDirs(dataDirs)
                         .setCheckpointOnClose(false)
                         .setChannelName("testlog")
                         .build();
  log.replay();
}
 
Example 2
Project: flume-release-1.7.0   File: TestLog.java   View Source Code Vote up 6 votes
@Test
public void testReplaySucceedsWithUnusedEmptyLogMetaDataFastReplay()
    throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
  FlumeEvent eventIn = TestUtils.newPersistableEvent();
  long transactionID = ++this.transactionID;
  FlumeEventPointer eventPointer = log.put(transactionID, eventIn);
  log.commitPut(transactionID); // this is not required since
  log.close();
  checkpointDir = Files.createTempDir();
  FileUtils.forceDeleteOnExit(checkpointDir);
  Assert.assertTrue(checkpointDir.isDirectory());
  log = new Log.Builder().setCheckpointInterval(1L)
                         .setMaxFileSize(MAX_FILE_SIZE)
                         .setQueueSize(CAPACITY)
                         .setCheckpointDir(checkpointDir)
                         .setLogDirs(dataDirs)
                         .setChannelName("testlog")
                         .setUseFastReplay(true)
                         .build();
  doTestReplaySucceedsWithUnusedEmptyLogMetaData(eventIn, eventPointer);
}
 
Example 3
Project: NGB-master   File: AbstractRESTController.java   View Source Code Vote up 6 votes
/**
 * Transfers content of the given {@code Multipart} entity to a temporary file.
 *
 * @param multipart {@code Multipart} used to handle file uploads
 * @return {@code File} represents a reference on a file that has been created
 * from the given {@code Multipart}
 * @throws IOException
 */
protected File transferToTempFile(final MultipartFile multipart) throws IOException {
    Assert.notNull(multipart);
    final File tmp = File.createTempFile(UUID.randomUUID().toString(), multipart.getOriginalFilename(),
        fileManager.getTempDir());
    multipart.transferTo(tmp);
    FileUtils.forceDeleteOnExit(tmp);
    return tmp;
}
 
Example 4
Project: NGB-master   File: AbstractRESTController.java   View Source Code Vote up 6 votes
/**
 * Joins back the file, transferred by chunks.
 *
 * @param multipart {@code Multipart} used to handle file chunk upload
 * @param id {@code Integer} identifies a specific file
 * @param fileName {@code String} original file name
 * @param chunk {@code int} current chunk number
 * @param chunks {@code int} overall number of chunks
 * @return {@code File} represents a reference on a temporary file that has been created
 * @throws IOException
 */
protected File saveChunkedFile(MultipartFile multipart, Integer id, String fileName, int chunk, int chunks)
        throws IOException {
    File dst = new File(fileManager.getTempDir(), id + fileName);

    if (Objects.equals(chunk, chunks - 1)) {
        FileUtils.forceDeleteOnExit(dst);
    }

    try (
            InputStream inputStream = multipart.getInputStream();
            OutputStream out = dst.exists() ? new BufferedOutputStream(new FileOutputStream(dst, true), BUF_SIZE) :
                new BufferedOutputStream(new FileOutputStream(dst), BUF_SIZE);
    ) {
        byte[] buffer = new byte[BUF_SIZE];
        int len = 0;
        while ((len = inputStream.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }
    }

    return dst;
}
 
Example 5
Project: Hydroangeas   File: MinecraftServerC.java   View Source Code Vote up 5 votes
public MinecraftServerC(HydroangeasClient instance,
                        MinecraftServerSyncPacket serverInfos,
                        int port)
{
    super(serverInfos.getMinecraftUUID(),
            serverInfos.getGame(),
            serverInfos.getMap(),
            serverInfos.getMinSlot(),
            serverInfos.getMaxSlot(),
            serverInfos.getOptions(),
            serverInfos.getStartupOptions()
            );
    this.instance = instance;

    this.coupaingServer = serverInfos.isCoupaingServer();

    this.hubID = serverInfos.getHubID();

    this.templateID = serverInfos.getTemplateID();

    this.timeToLive = serverInfos.getTimeToLive();

    this.serverFolder = new File(this.instance.getServerFolder(), serverInfos.getServerName());
    try
    {
        FileDeleteStrategy.FORCE.delete(serverFolder);
        FileUtils.forceDeleteOnExit(serverFolder);
    } catch (IOException e)
    {
        getLogger().warning(serverFolder + " will not be able to be deleted during JVM shutdown!");
    }
    this.port = port;

    this.weight = serverInfos.getWeight();
}
 
Example 6
Project: FunnyCreator   File: FunnyCleaner.java   View Source Code Vote up 5 votes
private void erase() throws Exception {
    FileUtils.deleteDirectory(FunnyConstants.MAVEN_DIRECTORY);
    FileUtils.forceDeleteOnExit(FunnyConstants.MAVEN_DIRECTORY);

    FileUtils.forceDeleteOnExit(FunnyConstants.REPOSITORY_DIRECTORY);
    FileUtils.deleteDirectory(FunnyConstants.REPOSITORY_DIRECTORY);
}
 
Example 7
Project: NGB-master   File: AbstractJUnitTest.java   View Source Code Vote up 5 votes
protected File getResourceFileCopy(String resourcePath) throws IOException {
    Resource resource = context.getResource(resourcePath);
    final File tmp = new File(fileManager.getTempDir(), resource.getFilename());
    FileUtils.copyFile(resource.getFile(), tmp);
    FileUtils.forceDeleteOnExit(tmp);
    return tmp;
}
 
Example 8
Project: osc-core   File: Schema.java   View Source Code Vote up 4 votes
@SuppressFBWarnings(value = "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE")
public static void createSchema(DBConnectionManager mgr) throws SQLException, KeyStoreProviderException, IOException, InterruptedException, VmidcException {
    try (Connection connection = mgr.getSQLConnection();
         Statement stmt = connection.createStatement()) {

    	connection.setAutoCommit(false);

        try {
            for (String statement : sqlStatements) {
                log.info("Execute sql: " + statement);
                stmt.execute(statement);
            }

            // Stamp db version
            stmt.execute("INSERT INTO release_info (id, version, db_version) VALUES (1, 0, " + ReleaseUpgradeMgr.TARGET_DB_VERSION + ");");

            // Add job archiving default settings - auto scheduled disabled, run weekly, purge jobs older then 1 year
            stmt.execute("INSERT INTO JOBS_ARCHIVE (id, version, auto_schedule, frequency, threshold_value, threshold_unit) VALUES "
                    + "(1, 0, 0, '" + FreqType.WEEKLY + "', 1, '" + ThresholdType.YEARS + "');");

            connection.commit();
        } catch (Exception ex) {
            log.error("Error while creating schema.", ex);

            try {
                connection.rollback();
            } catch (Exception he) {
                log.error("Error rolling back transaction", he);
            }

            // delete the newly created database to ensure we don't attempt to startup with a corrupted state
            try {
                FileUtils.forceDeleteOnExit(new File("vmiDCDB.h2.db"));
            } catch (IOException e) {
                log.error("Error deleting newly created database.", e);
            }

            throw ex;
        }
    }
}
 
Example 9
Project: flume-release-1.7.0   File: TestExecSource.java   View Source Code Vote up 4 votes
@Test
public void testProcess() throws InterruptedException, LifecycleException,
                                 EventDeliveryException, IOException {

  // Generates a random files for input\output
  File inputFile = File.createTempFile("input", null);
  File ouputFile = File.createTempFile("ouput", null);
  FileUtils.forceDeleteOnExit(inputFile);
  FileUtils.forceDeleteOnExit(ouputFile);

  // Generates input file with a random data set (10 lines, 200 characters each)
  FileOutputStream outputStream1 = new FileOutputStream(inputFile);
  for (int i = 0; i < 10; i++) {
    outputStream1.write(RandomStringUtils.randomAlphanumeric(200).getBytes());
    outputStream1.write('\n');
  }
  outputStream1.close();

  String command = SystemUtils.IS_OS_WINDOWS ?
                       String.format("cmd /c type %s", inputFile.getAbsolutePath()) :
                       String.format("cat %s", inputFile.getAbsolutePath());
  context.put("command", command);
  context.put("keep-alive", "1");
  context.put("capacity", "1000");
  context.put("transactionCapacity", "1000");
  Configurables.configure(source, context);

  source.start();
  Thread.sleep(2000);
  Transaction transaction = channel.getTransaction();

  transaction.begin();
  Event event;

  FileOutputStream outputStream = new FileOutputStream(ouputFile);

  while ((event = channel.take()) != null) {
    outputStream.write(event.getBody());
    outputStream.write('\n');
  }

  outputStream.close();
  transaction.commit();
  transaction.close();

  Assert.assertEquals(FileUtils.checksumCRC32(inputFile),
                      FileUtils.checksumCRC32(ouputFile));
}