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


Java FileUtils.touch方法代碼示例

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


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

示例1: touch

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
public TestFile touch() {
    try {
        FileUtils.touch(this);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    assertIsFile();
    return this;
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:10,代碼來源:TestFile.java

示例2: touch

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
public static void touch(File file) {
    try {
        FileUtils.touch(file);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:8,代碼來源:GFileUtils.java

示例3: batch_should_skip_on_second_scan

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Test
public void batch_should_skip_on_second_scan() throws IOException {
    long fileSize = ((Contants.REGION_SIZE * SlowFileProcessor.BATCH_SIZE) * 2) + 1;
    String workingDirectory = "/home/gaganis/IdeaProjects/DirectorySynchronizer/testdata/source";
    String fileName = "ubuntu-16.04.1-desktop-amd64.iso";
    File file = new File(fileName);
    updateAbsolutePath(file, workingDirectory, fileName);

    FileProcessor fileProcessor = getFileProcessor(fileSize, workingDirectory, file);
    BatchArea batchArea = fileProcessor.nextBatchArea();
    assertThat(batchArea.isSkip).isFalse();

    fileProcessor.doBeforeBatchByteRead();
    fileProcessor.process(
            new byte[(int) (Contants.REGION_SIZE * SlowFileProcessor.BATCH_SIZE)],
            batchArea);
    fileProcessor = getFileProcessor(fileSize, workingDirectory, file);
    batchArea = fileProcessor.nextBatchArea();
    assertThat(batchArea.isSkip).isTrue();
    FileUtils.touch(file.getAbsolutePath().toFile());

}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:23,代碼來源:FileProcessorBatchTest.java

示例4: testUploadFileStraightForward

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Test
public void testUploadFileStraightForward() throws Exception {

    setMock(setupMock());

    String fileName = UUID.randomUUID().toString() + ".txt";
    File upload = tmp.newFile(fileName);
    FileUtils.touch(upload);

    UploadFileToTransport.main(new String[] {
    "-u", SERVICE_USER,
    "-p", SERVICE_PASSWORD,
    "-e", SERVICE_ENDPOINT,
    "dummy-cmd",
    "8000042445", "L21K90002J", "HCP", upload.getAbsolutePath()
    });

    assertThat(changeId.getValue(), is(equalTo("8000042445")));
    assertThat(transportId.getValue(), is(equalTo("L21K90002J")));
    assertThat(filePath.getValue(), endsWith(fileName));
    assertThat(applicationId.getValue(), is(equalTo("HCP")));
}
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:23,代碼來源:UploadFileToTransportTest.java

示例5: train

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
public void train() {
    try {
        InputStreamFactory modelStream = new MarkableFileInputStreamFactory(
                new File(getClass().getClassLoader().getResource(TRAIN_INPUT).getFile())
        );
        final ObjectStream<String> lineStream = new PlainTextByLineStream(modelStream, "UTF-8");
        final ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(lineStream);

        final TrainingParameters mlParams = new TrainingParameters();
        mlParams.put(TrainingParameters.ITERATIONS_PARAM, 5000);
        mlParams.put(TrainingParameters.CUTOFF_PARAM, 5);

        final DoccatModel model = DocumentCategorizerME.train("en", sampleStream, mlParams, new DoccatFactory());
        final Path path = Paths.get(MODEL_OUTPUT);
        FileUtils.touch(path.toFile());
        try (OutputStream modelOut = new BufferedOutputStream(new FileOutputStream(path.toString()))) {
            model.serialize(modelOut);
        }
    } catch (Exception e) {
        LOGGER.error("an error occurred while training the sentiment analysis model", e);
        throw new IllegalStateException(e);
    }
}
 
開發者ID:kalnee,項目名稱:trivor-nlp,代碼行數:24,代碼來源:SentimentTraining.java

示例6: createTempFile

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Override
public File createTempFile(final String prefix, final String suffix) throws IOException {
    final File file = new File(folder, fileUniqueNameGenerator.get(prefix) + suffix);
    FileUtils.touch(file);
    tempFiles.add(file);
    return file;
}
 
開發者ID:subes,項目名稱:invesdwin-context-r,代碼行數:8,代碼來源:ModifiedTempFileService.java

示例7: testTouchSkip

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
public static void testTouchSkip(File file, Supplier<FileProcessor> fileProcessorSupplier, long byteArraySize) throws IOException, InterruptedException {
    FileProcessor fileProcessor = fileProcessorSupplier.get();

    fileProcessor.doBeforeFileRead(null);
    BatchArea batchArea = fileProcessor.nextBatchArea();
    assertThat(batchArea.isSkip).isFalse();

    fileProcessor.doBeforeBatchByteRead();
    fileProcessor.process(
            new byte[(int) byteArraySize],
            batchArea);

    //2nd pass
    fileProcessor = fileProcessorSupplier.get();
    fileProcessor.doBeforeFileRead(null);
    batchArea = fileProcessor.nextBatchArea();
    assertThat(batchArea.isSkip).isTrue();

    Thread.sleep(1000);//The 1 second precision of touch makes the test flaky, hence the sleep to make the touch roll to the next second
    FileUtils.touch(file.getAbsolutePath().toFile());

    //3rd pass
    fileProcessor = fileProcessorSupplier.get();
    fileProcessor.doBeforeFileRead(null);
    batchArea = fileProcessor.nextBatchArea();
    assertThat(batchArea.isSkip).isFalse();
}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:28,代碼來源:FileProcessorBatchTest.java

示例8: testImportFromM3U

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Test
public void testImportFromM3U() throws Exception {
    String username = "testUser";
    String playlistName = "test-playlist";
    StringBuilder builder = new StringBuilder();
    builder.append("#EXTM3U\n");
    File mf1 = folder.newFile();
    FileUtils.touch(mf1);
    File mf2 = folder.newFile();
    FileUtils.touch(mf2);
    File mf3 = folder.newFile();
    FileUtils.touch(mf3);
    builder.append(mf1.getAbsolutePath() + "\n");
    builder.append(mf2.getAbsolutePath() + "\n");
    builder.append(mf3.getAbsolutePath() + "\n");
    doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
    doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
    InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
    String path = "/path/to/"+playlistName+".m3u";
    playlistService.importPlaylist(username, playlistName, path, inputStream, null);
    verify(playlistDao).createPlaylist(actual.capture());
    verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());
    Playlist expected = new Playlist();
    expected.setUsername(username);
    expected.setName(playlistName);
    expected.setComment("Auto-imported from " + path);
    expected.setImportedFrom(path);
    expected.setShared(true);
    expected.setId(23);
    assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));
    List<MediaFile> mediaFiles = medias.getValue();
    assertEquals(3, mediaFiles.size());
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:34,代碼來源:PlaylistServiceTestImport.java

示例9: testImportFromPLS

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Test
public void testImportFromPLS() throws Exception {
    String username = "testUser";
    String playlistName = "test-playlist";
    StringBuilder builder = new StringBuilder();
    builder.append("[playlist]\n");
    File mf1 = folder.newFile();
    FileUtils.touch(mf1);
    File mf2 = folder.newFile();
    FileUtils.touch(mf2);
    File mf3 = folder.newFile();
    FileUtils.touch(mf3);
    builder.append("File1=" + mf1.getAbsolutePath() + "\n");
    builder.append("File2=" + mf2.getAbsolutePath() + "\n");
    builder.append("File3=" + mf3.getAbsolutePath() + "\n");
    doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
    doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
    InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
    String path = "/path/to/"+playlistName+".pls";
    playlistService.importPlaylist(username, playlistName, path, inputStream, null);
    verify(playlistDao).createPlaylist(actual.capture());
    verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());
    Playlist expected = new Playlist();
    expected.setUsername(username);
    expected.setName(playlistName);
    expected.setComment("Auto-imported from " + path);
    expected.setImportedFrom(path);
    expected.setShared(true);
    expected.setId(23);
    assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));
    List<MediaFile> mediaFiles = medias.getValue();
    assertEquals(3, mediaFiles.size());
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:34,代碼來源:PlaylistServiceTestImport.java

示例10: testImportFromXSPF

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Test
public void testImportFromXSPF() throws Exception {
    String username = "testUser";
    String playlistName = "test-playlist";
    StringBuilder builder = new StringBuilder();
    builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                   + "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n"
                   + "    <trackList>\n");
    File mf1 = folder.newFile();
    FileUtils.touch(mf1);
    File mf2 = folder.newFile();
    FileUtils.touch(mf2);
    File mf3 = folder.newFile();
    FileUtils.touch(mf3);
    builder.append("<track><location>file://" + mf1.getAbsolutePath() + "</location></track>\n");
    builder.append("<track><location>file://" + mf2.getAbsolutePath() + "</location></track>\n");
    builder.append("<track><location>file://" + mf3.getAbsolutePath() + "</location></track>\n");
    builder.append("    </trackList>\n" + "</playlist>\n");
    doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
    doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
    InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
    String path = "/path/to/"+playlistName+".xspf";
    playlistService.importPlaylist(username, playlistName, path, inputStream, null);
    verify(playlistDao).createPlaylist(actual.capture());
    verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());
    Playlist expected = new Playlist();
    expected.setUsername(username);
    expected.setName(playlistName);
    expected.setComment("Auto-imported from " + path);
    expected.setImportedFrom(path);
    expected.setShared(true);
    expected.setId(23);
    assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));
    List<MediaFile> mediaFiles = medias.getValue();
    assertEquals(3, mediaFiles.size());
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:37,代碼來源:PlaylistServiceTestImport.java

示例11: writeObject

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
static void writeObject(Attributes obj, String txUid, String classUid)
		throws IOException
{
	String studyUid = obj.getString(Tag.StudyInstanceUID);
	String seriesUid = obj.getString(Tag.SeriesInstanceUID);
	String instanceUid = obj.getString(Tag.SOPInstanceUID);

	File dcmFile = buildFile(studyUid, seriesUid, instanceUid, "dcm");
	File tmpFile = buildFile(studyUid, seriesUid, instanceUid, "tmp");
	File errFile = buildFile(studyUid, seriesUid, instanceUid, "err");
	try {
		if (errFile.isFile()) {
			logger.info("Overwriting error file: {}", errFile);

			FileUtils.deleteQuietly(errFile);
		}

		FileUtils.touch(tmpFile); // Create parent directories if needed

		try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
			if (UID.ImplicitVRLittleEndian.equals(txUid)) {
				// DicomOutputStream throws exception when writing dataset with LEI
				txUid = UID.ExplicitVRLittleEndian;
			}
			else if (UID.ExplicitVRBigEndianRetired.equals(txUid)) {
				// Should never happen, but just in case
				txUid = UID.ExplicitVRLittleEndian;

				logger.info("Trancoding dataset from big to "
							+ "little endian for: {}", dcmFile);
			}


			Attributes fmi = Attributes.createFileMetaInformation(instanceUid,
																  classUid,
																  txUid);

			DicomOutputStream dos = new DicomOutputStream(fos, txUid);
			dos.writeDataset(fmi, obj);
			dos.close();
		}

		Files.move(tmpFile.toPath(),
				   dcmFile.toPath(),
				   StandardCopyOption.ATOMIC_MOVE,
				   StandardCopyOption.REPLACE_EXISTING);
	}
	catch (Exception ex) {
		logger.warn("Unable save DICOM object to: " + dcmFile, ex);

		FileUtils.touch(errFile);
		FileUtils.deleteQuietly(tmpFile);
		FileUtils.deleteQuietly(dcmFile);

		if (ex instanceof IOException) {
			throw (IOException) ex;
		}
		else {
			throw new IOException(ex);
		}
	}
}
 
開發者ID:RSNA,項目名稱:dcmrs-broker,代碼行數:63,代碼來源:CacheManager.java

示例12: createUpgradeMarkerFile

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
private static void createUpgradeMarkerFile() {
    try {
        FileUtils.touch(new File(DB_UPGRADE_IN_PROGRESS_MARKER_FILE));
    } catch (IOException e) {
        log.error("Fail to create upgrade in progress marker file");
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:8,代碼來源:ReleaseUpgradeMgr.java

示例13: empty_file

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Test
public void empty_file() throws Exception {
  File tempFile = temp.newFile();
  FileUtils.touch(tempFile);

  FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
  assertThat(metadata.lines).isEqualTo(1);
  assertThat(metadata.originalLineOffsets).containsOnly(0);
  assertThat(metadata.lastValidOffset).isEqualTo(0);
}
 
開發者ID:instalint-org,項目名稱:instalint,代碼行數:11,代碼來源:FileMetadataTest.java

示例14: buildFileDatas

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
protected List<FileData> buildFileDatas(String namespace, EventType eventType, int start, int count, boolean create)
                                                                                                                    throws IOException {
    List<FileData> files = new ArrayList<FileData>();

    for (int i = start; i < count; i++) {
        FileData fileData = new FileData();
        fileData.setNameSpace(namespace); // namespace is null means file is
                                          // local file
        fileData.setEventType(eventType);
        fileData.setPairId(i % NUMBER_OF_FILE_DATA_COPIES);
        fileData.setPath(ROOT_DIR.getAbsolutePath() + "/target/" + eventType.getValue() + i);

        String parentPath = ROOT_DIR.getPath();
        if (namespace != null) {
            parentPath = parentPath + "/" + namespace;
        }
        File file = new File(parentPath, fileData.getPath());
        if (!file.exists() && create) {
            FileUtils.touch(file);
        }

        fileData.setSize(file.exists() ? file.length() : 0);
        fileData.setLastModifiedTime(file.exists() ? file.lastModified() : Calendar.getInstance().getTimeInMillis());
        fileData.setTableId(TABLE_ID);

        files.add(fileData);
    }

    return files;
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:31,代碼來源:FileLoadActionTest.java

示例15: processTemplate

import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
/**
 * 處理模板生成.
 *
 * @param model model
 * @param files files
 * @param templateDirectory templateDirectoryFile
 * @throws IOException io exception
 */
private void processTemplate(FreemarkerHelper templateHelper, Map<String, Object> model, List<File> files,
                             File templateDirectory) throws IOException {
    for (File file : files) {
        String fileName = file.getName();
        String targetName = templateHelper.processToString(model, fileName.replace(FREEMARKER_TEMPLATE_SUFFIX, ""));
        File targetFile = getTargetFile(templateHelper, model, templateDirectory, file, outDirectoryFile,
                                        targetName);
        FileUtils.touch(targetFile);
        String templateName = getRelativizeTemplateFile(templateDirectory, file).toPath().toString();
        templateHelper.processToFile(model, templateName, targetFile, "UTF-8");
    }
}
 
開發者ID:sgota,項目名稱:tkcg,代碼行數:21,代碼來源:Generator.java


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