public static ContentBuilder generate(ValueWriter writer) { return new ContentBuilder(new JacksonJsonGenerator(new FastByteArrayOutputStream()), writer); }
@BeforeClass public static void beforeClass() { out = new FastByteArrayOutputStream(); }
@Override protected OutputStream openWrite() throws IOException { this.exists = true; this.fileBytes.reset(); return new FastByteArrayOutputStream(fileBytes); }
static BytesArray writeSerializablePartition(PartitionDefinition def) throws IOException { FastByteArrayOutputStream out = new FastByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); try { oos.writeObject(def); oos.flush(); return out.bytes(); } finally { oos.close(); } }
@BeforeClass public static void beforeClass() { out = new FastByteArrayOutputStream(); }
@BeforeClass public static void beforeClass() { out = new FastByteArrayOutputStream(); }
@BeforeClass public static void beforeClass() { out = new FastByteArrayOutputStream(); }
@BeforeClass public static void beforeClass() { out = new FastByteArrayOutputStream(); }
static BytesArray writeWritablePartition(PartitionDefinition def) throws IOException { FastByteArrayOutputStream out = new FastByteArrayOutputStream(); DataOutputStream da = new DataOutputStream(out); try { def.write(da); da.flush(); return out.bytes(); } finally { da.close(); } }
private static String readValueAsString(Parser parser) { FastByteArrayOutputStream out = new FastByteArrayOutputStream(256); JacksonJsonGenerator generator = new JacksonJsonGenerator(out); traverse(parser, generator); generator.close(); return out.toString(); }
protected void doWriteObject(Object object, BytesArray storage, ValueWriter<?> writer) { FastByteArrayOutputStream bos = new FastByteArrayOutputStream(storage); ContentBuilder.generate(bos, writer).value(object).flush().close(); }
@Override public String toString() { FastByteArrayOutputStream out = new FastByteArrayOutputStream(256); JacksonJsonGenerator generator = new JacksonJsonGenerator(out); generator.writeBeginObject(); toJson(generator); generator.writeEndObject(); generator.close(); return out.toString(); } }
@Test public void testMapWithArrayReadWrite() throws Exception { LinkedMapWritable written = new LinkedMapWritable(); ArrayWritable array = new WritableArrayWritable(Text.class); array.set(new Writable[] { new Text("one") , new Text("two"), new Text("three")} ); written.put(new Text("foo"), array); FastByteArrayOutputStream out = new FastByteArrayOutputStream(); DataOutputStream da = new DataOutputStream(out); written.write(da); da.close(); LinkedMapWritable read = new LinkedMapWritable(); read.readFields(new DataInputStream(new FastByteArrayInputStream(out.bytes()))); assertThat(read.size(), is(written.size())); assertThat(read.toString(), is(written.toString())); }
static BytesArray searchRequest(QueryBuilder query) { FastByteArrayOutputStream out = new FastByteArrayOutputStream(256); JacksonJsonGenerator generator = new JacksonJsonGenerator(out); try { generator.writeBeginObject(); generator.writeFieldName("query"); generator.writeBeginObject(); query.toJson(generator); generator.writeEndObject(); generator.writeEndObject(); } finally { generator.close(); } return out.bytes(); }
@Test public void listKeystoreEmpty() throws Exception { BytesArray storeData = new BytesArray(128); KeystoreWrapper.newStore().build().saveKeystore(new FastByteArrayOutputStream(storeData)); TestPrompt console = new TestPrompt(); KeytoolHarness keytool = new KeytoolHarness(console, Keytool.Command.LIST, true, storeData); assertThat(keytool.run(null, false, false), equalTo(0)); assertThat(console.getOutput(), equalTo("")); assertThat(console.hasInputLeft(), is(false)); assertThat(keytool.ksExists(), is(true)); assertThat(keytool.fileBytes.length(), is(not(0))); }
@Test public void testEmptyArrayReadWrite() throws Exception { ArrayWritable array = new WritableArrayWritable(Text.class); FastByteArrayOutputStream out = new FastByteArrayOutputStream(); DataOutputStream da = new DataOutputStream(out); array.write(da); da.close(); WritableArrayWritable waw = new WritableArrayWritable(NullWritable.class); waw.readFields(new DataInputStream(new FastByteArrayInputStream(out.bytes()))); assertSame(array.getValueClass(), waw.getValueClass()); } }
@Test public void removeMissingKey() throws Exception { BytesArray storeData = new BytesArray(128); KeystoreWrapper ks = KeystoreWrapper.newStore().build(); ks.saveKeystore(new FastByteArrayOutputStream(storeData)); TestPrompt console = new TestPrompt(); KeytoolHarness keytool = new KeytoolHarness(console, Keytool.Command.REMOVE, true, storeData); assertThat(keytool.run("test.password.1", false, false), equalTo(6)); assertThat(console.getOutput(), equalTo("ERROR: Setting [test.password.1] does not exist in the keystore.\n")); assertThat(console.hasInputLeft(), is(false)); assertThat(keytool.ksExists(), is(true)); assertThat(keytool.fileBytes.length(), is(not(0))); }
static QueryBuilder randomRawQueryStringQuery(Random rand, int level) { QueryBuilder query = randomQuery(rand); FastByteArrayOutputStream out = new FastByteArrayOutputStream(256); Generator generator = new JacksonJsonGenerator(out); generator.writeBeginObject(); query.toJson(generator); generator.writeEndObject(); generator.close(); try { return new RawQueryBuilder(out.toString().trim(), false); } catch (IOException e) { throw new IllegalArgumentException("failed to parse raw query", e); } }
@Test public void addKeyStdIn() throws Exception { BytesArray storeData = new BytesArray(128); KeystoreWrapper ks = KeystoreWrapper.newStore().build(); ks.saveKeystore(new FastByteArrayOutputStream(storeData)); TestPrompt console = new TestPrompt(); console.addInput("blahh"); KeytoolHarness keytool = new KeytoolHarness(console, Keytool.Command.ADD, true, storeData); assertThat(keytool.run("test.password.1", true, false), equalTo(0)); assertThat(console.getOutput(), equalTo("")); assertThat(console.hasInputLeft(), is(false)); assertThat(keytool.ksExists(), is(true)); assertThat(keytool.fileBytes.length(), is(not(0))); ks = KeystoreWrapper.loadStore(new FastByteArrayInputStream(keytool.fileBytes)).build(); assertThat(ks.getSecureSetting("test.password.1"), equalTo("blahh")); }
@Test public void addKey() throws Exception { BytesArray storeData = new BytesArray(128); KeystoreWrapper ks = KeystoreWrapper.newStore().build(); ks.saveKeystore(new FastByteArrayOutputStream(storeData)); TestPrompt console = new TestPrompt(); console.addInput("blahh"); KeytoolHarness keytool = new KeytoolHarness(console, Keytool.Command.ADD, true, storeData); assertThat(keytool.run("test.password.1", false, false), equalTo(0)); assertThat(console.getOutput(), equalTo("")); assertThat(console.hasInputLeft(), is(false)); assertThat(keytool.ksExists(), is(true)); assertThat(keytool.fileBytes.length(), is(not(0))); ks = KeystoreWrapper.loadStore(new FastByteArrayInputStream(keytool.fileBytes)).build(); assertThat(ks.getSecureSetting("test.password.1"), equalTo("blahh")); }