@Test public void testTouch() throws Exception { Local parent = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random()); Local l = new Local(parent, UUID.randomUUID().toString()); final DefaultLocalTouchFeature f = new DefaultLocalTouchFeature(); f.touch(l); assertTrue(parent.exists()); assertTrue(l.exists()); f.touch(l); assertTrue(l.exists()); f.touch(l); l.delete(); parent.delete(); }
@Override public void touch(final Local file) throws AccessDeniedException { try { try { Files.createFile(Paths.get(file.getAbsolute())); } catch(NoSuchFileException e) { final Local parent = file.getParent(); new DefaultLocalDirectoryFeature().mkdir(parent); if(log.isDebugEnabled()) { log.debug(String.format("Created folder %s", parent)); } Files.createFile(Paths.get(file.getAbsolute())); } catch(FileAlreadyExistsException e) { log.warn(String.format("File %s already exists", file)); if(Files.isDirectory(Paths.get(file.getAbsolute()))) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } return; } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } if(log.isDebugEnabled()) { log.debug(String.format("Created file %s", file)); } }
DefaultLocalTouchFeature implements Touch { @Override public void touch(final Local file) throws AccessDeniedException { try { try { Files.createFile(Paths.get(file.getAbsolute())); } catch(NoSuchFileException e) { final Local parent = file.getParent(); new DefaultLocalDirectoryFeature().mkdir(parent); if(log.isDebugEnabled()) { log.debug(String.format("Created folder %s", parent)); } Files.createFile(Paths.get(file.getAbsolute())); } catch(FileAlreadyExistsException e) { log.warn(String.format("File %s already exists", file)); if(Files.isDirectory(Paths.get(file.getAbsolute()))) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } return; } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } if(log.isDebugEnabled()) { log.debug(String.format("Created file %s", file)); } } }
DefaultLocalTouchFeature implements Touch { @Override public void touch(final Local file) throws AccessDeniedException { try { try { Files.createFile(Paths.get(file.getAbsolute())); } catch(NoSuchFileException e) { final Local parent = file.getParent(); new DefaultLocalDirectoryFeature().mkdir(parent); if(log.isDebugEnabled()) { log.debug(String.format("Created folder %s", parent)); } Files.createFile(Paths.get(file.getAbsolute())); } catch(FileAlreadyExistsException e) { log.warn(String.format("File %s already exists", file)); if(Files.isDirectory(Paths.get(file.getAbsolute()))) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } return; } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } if(log.isDebugEnabled()) { log.debug(String.format("Created file %s", file)); } }  }
DefaultLocalTouchFeature implements Touch { @Override public void touch(final Local file) throws AccessDeniedException { try { try { Files.createFile(Paths.get(file.getAbsolute())); } catch(NoSuchFileException e) { final Local parent = file.getParent(); new DefaultLocalDirectoryFeature().mkdir(parent); if(log.isDebugEnabled()) { log.debug(String.format("Created folder %s", parent)); } Files.createFile(Paths.get(file.getAbsolute())); } catch(FileAlreadyExistsException e) { log.warn(String.format("File %s already exists", file)); if(Files.isDirectory(Paths.get(file.getAbsolute()))) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } return; } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } if(log.isDebugEnabled()) { log.debug(String.format("Created file %s", file)); } }  @Override void touch(final Local file); }
DefaultLocalTouchFeature implements Touch { @Override public void touch(final Local file) throws AccessDeniedException { try { try { Files.createFile(Paths.get(file.getAbsolute())); } catch(NoSuchFileException e) { final Local parent = file.getParent(); new DefaultLocalDirectoryFeature().mkdir(parent); if(log.isDebugEnabled()) { log.debug(String.format("Created folder %s", parent)); } Files.createFile(Paths.get(file.getAbsolute())); } catch(FileAlreadyExistsException e) { log.warn(String.format("File %s already exists", file)); if(Files.isDirectory(Paths.get(file.getAbsolute()))) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } return; } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e); } if(log.isDebugEnabled()) { log.debug(String.format("Created file %s", file)); } }  @Override void touch(final Local file);  }