List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:org.sipfoundry.voicemail.VmMessage.java
/** * Forward this message (with optional recorded comments) to the inbox of a mailbox * /*from w w w . ja va 2s .co m*/ * @param mailbox * @param recording * @return */ public VmMessage forward(Mailbox mailbox, Message recording) { VmMessage me = new VmMessage(); // Generate the next message ID me.m_messageId = nextMessageId(mailbox.getMailstoreDirectory() + "/.."); // Generate the MessageDescriptor; me.m_messageDescriptor = new MessageDescriptor(); me.m_messageDescriptor.setId(mailbox.getUser().getIdentity()); me.m_messageDescriptor.setFromUri(recording.getFromUri()); me.m_messageDescriptor.setDurationSecs(recording.getDuration() + getDuration()); me.m_messageDescriptor.setTimestamp(recording.getTimestamp()); me.m_messageDescriptor.setSubject("Fwd:Voice Message " + m_messageId); me.m_messageDescriptor.setPriority(recording.getPriority()); Vector<User> otherRecipients = recording.getOtherRecipeints(); if (otherRecipients != null) { for (User recip : otherRecipients) { if (!recip.getUserName().equals(mailbox.getUser().getUserName())) { me.m_messageDescriptor.addOtherRecipient(recip.getUserName()); } } } if (recording.getPriority() == Priority.URGENT) { me.m_urgent = true; } // Copy into the inbox of the mailbox File directory = new File(mailbox.getInboxDirectory()); String baseName = mailbox.getInboxDirectory() + me.m_messageId; me.m_audioFile = new File(baseName + "-00.wav"); me.m_descriptorFile = new File(baseName + "-00.xml"); me.m_statusFile = new File(baseName + "-00.sta"); me.m_urgentFile = new File(baseName + "-00.urg"); me.m_combinedAudioFile = new File(baseName + "-FW.wav"); // Copy (with the new message ID in the names) all the files String operation = "copying stuff"; try { me.m_unHeard = true; operation = "creating status file " + me.m_statusFile.getPath(); FileUtils.touch(me.m_statusFile); if (me.m_urgent) { operation = "creating urgent file " + me.m_urgentFile.getPath(); LOG.debug("VmMessage::newMessage " + operation); FileUtils.touch(me.m_urgentFile); } operation = "copying audio file " + m_audioFile.getPath(); // The old audio file becomes "originalAudioFile" as NewID-01.wav String newName = String.format("%s-%s.%s", me.m_messageId, "01", "wav"); me.m_originalAudioFile = new File(directory, newName); FileUtils.copyFile(m_audioFile, me.m_originalAudioFile, true); operation = "copying descriptor file " + m_audioFile.getPath(); // The old descriptor file becomes "originalDescriptorFile" as NewID-01.xml newName = String.format("%s-%s.%s", me.m_messageId, "01", "xml"); me.m_originalDescriptorFile = new File(directory, newName); FileUtils.copyFile(m_descriptorFile, me.m_originalDescriptorFile, true); // The recording (if any) becomes the audioFile as NewID-00.wav if (recording.getWavFile() != null) { File tempFile = recording.getWavFile(); operation = "copying comments .wav file to " + me.m_audioFile.getPath(); FileUtils.copyFile(tempFile, me.m_audioFile, true); // Combine the new and the old file into one bigger .wav as NewID-FW.wav operation = "combining " + me.m_audioFile.getPath() + " with " + me.m_originalAudioFile.getPath(); concatAudio(me.m_combinedAudioFile, me.m_audioFile, me.m_originalAudioFile); } else { FileUtils.touch(me.m_audioFile); // Create an empty NewID-00.wav file // Copy the old audiofile by itself to NewID-FW.wav FileUtils.copyFile(me.m_originalAudioFile, me.m_combinedAudioFile, true); } operation = "creating messageDescriptor " + me.m_descriptorFile.getPath(); new MessageDescriptorWriter().writeObject(me.m_messageDescriptor, me.m_descriptorFile); } catch (Exception e) { LOG.error("VmMessage::copyMessage error while " + operation, e); return null; } LOG.info("VmMessage::forward created message " + me.m_descriptorFile.getPath()); Mwi.sendMWI(mailbox); me.sendToEmail(mailbox); return me; }
From source file:org.sipfoundry.voicemail.VmMessage.java
public void markUnheard() { if (!m_unHeard) { if (m_statusFile != null) { String operation = "update status"; try { operation = "creating status file " + m_statusFile.getPath(); FileUtils.touch(m_statusFile); LOG.info(String.format("VmMessage::markHeard %s marked unheard", m_descriptorFile.getPath())); m_unHeard = false;/*from w w w . j a va 2s . co m*/ } catch (IOException e) { LOG.error("VmMessage::markUnHeard error while " + operation, e); } } } }
From source file:org.sonar.api.batch.fs.internal.FileMetadataTest.java
@Test public void empty_file() throws Exception { File tempFile = temp.newFile(); FileUtils.touch(tempFile); Metadata metadata = new FileMetadata().readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName());/*from w w w . j a va 2 s . com*/ assertThat(metadata.lines()).isEqualTo(1); assertThat(metadata.nonBlankLines()).isEqualTo(0); assertThat(metadata.hash()).isNotEmpty(); assertThat(metadata.originalLineOffsets()).containsOnly(0); assertThat(metadata.lastValidOffset()).isEqualTo(0); }
From source file:org.sonar.api.utils.internal.DefaultTempFolderTest.java
@Test public void clean_deletes_non_empty_directory() throws Exception { File dir = temp.newFolder();/* w w w. j ava2 s.c o m*/ FileUtils.touch(new File(dir, "foo.txt")); DefaultTempFolder underTest = new DefaultTempFolder(dir); underTest.clean(); assertThat(dir).doesNotExist(); }
From source file:org.sonar.application.AppFileSystemTest.java
@Test public void fail_if_required_directory_is_a_file() throws Exception { // <home>/data is missing FileUtils.forceMkdir(webDir);/*from www . j a v a 2 s . co m*/ FileUtils.forceMkdir(logsDir); FileUtils.touch(dataDir); expectedException.expect(IllegalStateException.class); expectedException.expectMessage( "Property 'sonar.path.data' is not valid, not a directory: " + dataDir.getAbsolutePath()); underTest.reset(); }
From source file:org.sonar.application.command.CommandFactoryImplTest.java
private void prepareEsFileSystem() throws IOException { FileUtils.touch(new File(homeDir, "elasticsearch/bin/elasticsearch")); FileUtils.touch(new File(homeDir, "elasticsearch/bin/elasticsearch.bat")); }
From source file:org.sonar.application.config.JdbcSettingsTest.java
@Test public void checkAndComplete_sets_driver_path_for_oracle() throws Exception { File driverFile = new File(homeDir, "extensions/jdbc-driver/oracle/ojdbc6.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL, "jdbc:oracle:thin:@localhost/XE"); underTest.accept(props);//ww w . j av a 2s .co m assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); }
From source file:org.sonar.application.config.JdbcSettingsTest.java
@Test public void sets_driver_path_for_h2() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/h2/h2.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar"); underTest.accept(props);//from w w w .j a v a 2 s . c om assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); }
From source file:org.sonar.application.config.JdbcSettingsTest.java
@Test public void checkAndComplete_sets_driver_path_for_postgresql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/postgresql/pg.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL, "jdbc:postgresql://localhost/sonar"); underTest.accept(props);/*from w w w. ja v a 2s . c o m*/ assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); }
From source file:org.sonar.application.config.JdbcSettingsTest.java
@Test public void checkAndComplete_sets_driver_path_for_mssql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/mssql/sqljdbc4.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL, "jdbc:sqlserver://localhost/sonar;SelectMethod=Cursor"); underTest.accept(props);// w ww . j a v a 2 s .c om assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); }