CleanupOldFilesPipe extends FixedForwardPipe { @Override public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException { try { String filename; if (StringUtils.isNotEmpty(getFilePattern())) { filename = FileUtils.getFilename(getParameterList(), session, "", getFilePattern()); } else { if (StringUtils.isNotEmpty(getFilePatternSessionKey())) { filename = FileUtils.getFilename(getParameterList(), session, "", (String)session.get(getFilePatternSessionKey())); } else { if (StringUtils.isEmpty(message.asString())) { throw new PipeRunException(this, "input empty, but should contain filename to delete"); } else { File in = new File(message.asString()); filename = in.getName(); } } } List delFiles = getFilesForDeletion(filename); if (delFiles != null && delFiles.size() > 0) { for (Iterator fileIt = delFiles.iterator(); fileIt.hasNext();) { File file = (File)fileIt.next(); String curfilename=file.getName(); if (file.delete()) { log.info(getLogPrefix(session)+"deleted file ["+file.getAbsolutePath()+"]"); } else { log.warn(getLogPrefix(session)+"could not delete file ["+file.getAbsolutePath()+"]"); } } } else { log.info(getLogPrefix(session)+"no files match pattern ["+filename+"]"); } if (isDeleteEmptySubdirectories()) { File file = new File(filename); if (file.exists()) { deleteEmptySubdirectories(getLogPrefix(session), file, 0); } } return new PipeRunResult(getForward(), message); } catch(Exception e) { throw new PipeRunException(this, "Error while deleting file(s)", e); } }  @Override PipeRunResult doPipe(Message message, IPipeLineSession session); @IbisDoc({"files that match this pattern will be deleted. parameters of the pipe are applied to this pattern. if this attribute is not set, the input of the pipe is interpreted as the file to be removed", ""}) void setFilePattern(String string); String getFilePattern(); @IbisDoc({"", " "}) void setFilePatternSessionKey(String string); String getFilePatternSessionKey(); @IbisDoc({"time in milliseconds after last modification that must have passed at least before a file will be deleted (set to negative value to disable)", "0"}) void setLastModifiedDelta(long l); long getLastModifiedDelta(); @IbisDoc({"when <code>true</code>, files in subdirectories will be deleted, too", "false"}) void setSubdirectories(boolean b); boolean isSubdirectories(); @IbisDoc({"when <code>true</code>, empty subdirectories will be deleted, too", "false"}) void setDeleteEmptySubdirectories(boolean b); boolean isDeleteEmptySubdirectories(); @IbisDoc({"filter of files to delete. if not set and a directory is specified, all files in the directory are interpreted to be deleted", ""}) void setWildcard(String string); String getWildcard(); @IbisDoc({"filter of files to be excluded for deletion", ""}) void setExcludeWildcard(String excludeWildcard); String getExcludeWildcard(); @IbisDoc({"minimal age of file in milliseconds, to avoid deleting a file while it is still being written (only used when wildcard is set) (set to 0 or negative value to disable)", "1000 [ms]"}) void setMinStableTime(long minStableTime); long getMinStableTime();  }
@Test(expected = PipeRunException.class) public void emptyInput() throws PipeRunException { doPipe(pipe, "", session); }