/** * Write lines to a text file with UTF-8 encoding. Separate each line with a newline ("\n" character). If the writing or sending fails, * the file is deleted. * <p> * If the filename ends with .gz, then the data is automatically GZipped. * </p> * @param file the file to save the text to * * @return an Output for storing text in a file */ public static Output<String, IOException> text( final File file ) // END SNIPPET: method { return text( file, "UTF-8" ); }
/** * Do nothing. Use this if you have all logic in filters and/or specifications * * @param <T> The item type. * * @return An Output instance that ignores all data. */ public static <T> Output<T, RuntimeException> noop() // END SNIPPET: method { return withReceiver( new Receiver<T, RuntimeException>() { @Override public void receive( T item ) throws RuntimeException { // Do nothing } } ); }
@Test public void testIOString() throws Exception { StringBuilder sb = new StringBuilder(); iterable( byteCollection() ).transferTo( map( valueSerialization.serialize(), text( sb ) ) ); String output = sb.toString(); List<Byte> list = new ArrayList<Byte>(); text( output ).transferTo( map( valueSerialization.deserialize( Byte.class ), collection( list ) ) ); assertEquals( byteCollection(), list ); }