@Override public ModelOutput<T> createOutput( Class<? extends T> dataType, String path, OutputStream stream) throws IOException, InterruptedException { JsonFormat<T> format = getJsonFormat(); Set<OutputOption> options = OUTPUT_OPTS; OutputStream destination = decorate(stream); return new DecoratedOutput(format.open(path, destination, options), new StringOption(path)); }
@Override public ModelInput<T> createInput( Class<? extends T> dataType, String path, InputStream stream, long offset, long fragmentSize) throws IOException, InterruptedException { JsonFormat<T> format = getJsonFormat(); Set<InputOption> options = offset == 0 ? INPUT_OPTS_HEAD : INPUT_OPTS_REST; InputStream source = decorate(stream, offset, fragmentSize); return new DecoratedInput(format.open(path, source, options), new StringOption(path)); }
/** * test for text values. * @throws Exception if failed */ @Test public void text_values() throws Exception { assertRestorable(new StringOption("Hello")); assertRestorable(new StringOption("\u3042\u3044\u3046\u3048\u304a")); assertRestorable(new StringOption("\",\r\n\t ")); assertRestorable(new StringOption()); }
/** * test for text values. * @throws Exception if failed */ @Test public void text_values_quote() throws Exception { quote.add(0); assertRestorable(new StringOption("Hello")); assertRestorable(new StringOption("\u3042\u3044\u3046\u3048\u304a")); assertRestorable(new StringOption("\",\r\n\t ")); }
/** * append - string option. */ @Test public void append_option() { StringOption value = new StringOption("Hello"); StringOptionUtil.append(value, new StringOption(", world!")); StringOptionUtil.trim(value); assertThat(value, is(new StringOption("Hello, world!"))); }
/** * trim - nothing. */ @Test public void trim_trailing() { StringOption value = new StringOption("Hello, world! "); StringOptionUtil.trim(value); assertThat(value, is(new StringOption("Hello, world!"))); }
/** * trim - nothing. */ @Test public void trim_nothing() { StringOption value = new StringOption("Hello, world!"); StringOptionUtil.trim(value); assertThat(value, is(new StringOption("Hello, world!"))); }
/** * parse w/ null. */ @Test public void parse_null() { StringOption option = new StringOption(null); Date date = Date.valueOf(option, Date.Format.SIMPLE); assertThat(date, is(nullValue())); }
/** * parse w/ null. */ @Test public void parse_null() { StringOption option = new StringOption(null); DateTime time = DateTime.valueOf(option, DateTime.Format.SIMPLE); assertThat(time, is(nullValue())); }
/** * parse - broken UTF-16. */ @Test public void parse_broken() { StringOptionFieldAdapter adapter = StringOptionFieldAdapter.builder().build(); checkMalformed(adapter, String.valueOf(CP_BEER.charAt(0)), new StringOption()); }
/** * test for set w/ text. */ @Test public void text() { StringOption option = new StringOption(); option.modify(new Text("Hello, world!")); assertThat(option.isNull(), is(false)); assertThat(option.get().toString(), is("Hello, world!")); }
/** * test for Writable w/ null. */ @Test public void writableOption() { StringOption option = new StringOption(); StringOption restored = restore(option); assertThat(restored.isNull(), is(true)); }
/** * parse w/ option value. */ @Test public void parse_option() { StringOption option = new StringOption("20100615"); Date date = Date.valueOf(option, Date.Format.SIMPLE); assertThat(date.getYear(), is(2010)); assertThat(date.getMonth(), is(6)); assertThat(date.getDay(), is(15)); }
/** * test for or w/ string. */ @Test public void stringOr() { StringOption option = new StringOption(); assertThat(option.or("Hello"), is("Hello")); assertThat(option.isNull(), is(true)); option.modify("World"); assertThat(option.or("Other"), is("World")); }
/** * emit - empty. */ @Test public void emit_empty() { StringOptionFieldAdapter adapter = StringOptionFieldAdapter.builder().build(); checkEmit(adapter, new StringOption(""), ""); }
/** * parse - surrogate pair. */ @Test public void parse_surrogate_pair() { StringOptionFieldAdapter adapter = StringOptionFieldAdapter.builder().build(); checkParse(adapter, CP_BEER, new StringOption(CP_BEER)); }
/** * parse - empty. */ @Test public void parse_empty() { StringOptionFieldAdapter adapter = StringOptionFieldAdapter.builder().build(); checkParse(adapter, "", new StringOption("")); }
/** * emit. */ @Test public void emit() { StringOptionFieldAdapter adapter = StringOptionFieldAdapter.builder().build(); checkEmit(adapter, new StringOption("Hello, world!"), "Hello, world!"); }
/** * test for Writable. */ @Test public void writable() { StringOption option = new StringOption(); option.modify("Hello"); StringOption restored = restore(option); assertThat(option.getAsString(), is(restored.getAsString())); }
/** * emit - null. */ @Test public void emit_null_formatted() { StringOptionFieldAdapter adapter = StringOptionFieldAdapter.builder().withNullFormat("null").build(); checkEmit(adapter, new StringOption(), "null"); } }