本文整理汇总了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;
}
示例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);
}
}
示例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());
}
示例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")));
}
示例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);
}
}
示例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;
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
}
}
示例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");
}
}
示例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);
}
示例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;
}
示例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");
}
}