当前位置: 首页>>代码示例>>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;未经允许,请勿转载。