ChecksumPipe extends FixedForwardPipe { @Override public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException { String result; try { ChecksumGenerator cg=createChecksumGenerator(); if (isInputIsFile()) { byte barr[]=new byte[1000]; FileInputStream fis=new FileInputStream(message.asString()); int c; while ((c=fis.read(barr))>=0) { cg.update(barr,c); } } else { byte barr[]; if (StringUtils.isEmpty(getCharset())) { barr=message.asByteArray(); } else { barr=message.asByteArray(getCharset()); } cg.update(barr,barr.length); } result=cg.getResult(); return new PipeRunResult(getForward(),result); } catch (Exception e) { throw new PipeRunException(this,"cannot calculate ["+getType()+"]"+(isInputIsFile()?" on file ["+message+"]":" using charset ["+getCharset()+"]"),e); } }  @Override void configure(); @Override PipeRunResult doPipe(Message message, IPipeLineSession session); @IbisDoc({"character encoding to be used to encode message before calculating checksum", "utf-8"}) void setCharset(String string); String getCharset(); @IbisDoc({"type of checksum to be calculated. must be one of md5, sha, crc32, adler32", "md5"}) void setType(String string); String getType(); @IbisDoc({"when set <code>true</code>, the input is assumed to be a filename; otherwise the input itself is used in the calculations", "false"}) void setInputIsFile(boolean b); boolean isInputIsFile(); static final String CHECKSUM_MD5; static final String CHECKSUM_SHA; static final String CHECKSUM_CRC32; static final String CHECKSUM_ADLER32; }
@Test(expected = PipeRunException.class) public void cantCalculate() throws PipeRunException { doPipe(pipe, new Message((String)null), session); }