當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtils.forceDeleteOnExit方法代碼示例

本文整理匯總了Java中org.apache.commons.io.FileUtils.forceDeleteOnExit方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtils.forceDeleteOnExit方法的具體用法?Java FileUtils.forceDeleteOnExit怎麽用?Java FileUtils.forceDeleteOnExit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.io.FileUtils的用法示例。


在下文中一共展示了FileUtils.forceDeleteOnExit方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@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();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestLog.java

示例2: testReplaySucceedsWithUnusedEmptyLogMetaDataFastReplay

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@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);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestLog.java

示例3: transferToTempFile

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:17,代碼來源:AbstractRESTController.java

示例4: saveChunkedFile

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:34,代碼來源:AbstractRESTController.java

示例5: MinecraftServerC

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
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();
}
 
開發者ID:SamaGames,項目名稱:Hydroangeas,代碼行數:36,代碼來源:MinecraftServerC.java

示例6: erase

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
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);
}
 
開發者ID:FunnyGuilds,項目名稱:FunnyCreator,代碼行數:8,代碼來源:FunnyCleaner.java

示例7: getResourceFileCopy

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
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;
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:8,代碼來源:AbstractJUnitTest.java

示例8: createSchema

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@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;
        }
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:42,代碼來源:Schema.java

示例9: testProcess

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@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));
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:49,代碼來源:TestExecSource.java


注:本文中的org.apache.commons.io.FileUtils.forceDeleteOnExit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。