/** * Checks an argument and throws an exception if null. */ public static <T> T checkNotNull(T argument, String argumentName) throws NullArgumentException { if(argument==null) throw new NullArgumentException(argumentName); return argument; }
/** * Copies all information from one stream to an appendable. * * @return the number of bytes copied * * @see BufferManager#getChars() */ public static long copy(Reader in, Appendable out) throws IOException { if(in == null) throw new NullArgumentException("in"); if(out == null) throw new NullArgumentException("out"); char[] buff = BufferManager.getChars(); try { long totalChars = 0; int numChars; while((numChars = in.read(buff, 0, BufferManager.BUFFER_SIZE))!=-1) { out.append(new String(buff, 0, numChars)); totalChars += numChars; } return totalChars; } finally { BufferManager.release(buff, false); } }