/** * @return the scroll search hit in the original raw JSON format */ public InputStream getHitContents() { return new FastByteArrayInputStream(hit); } }
@Override public String convert(DeserializationFailure entry) { return String.format( "Dropping malformed scroll search hit due to error [%s]:%nEntry Contents:%n%s", entry.getException().getMessage(), ((FastByteArrayInputStream) entry.getHitContents()).bytes().toString() ); } }
@Test public void markAndReset() throws Exception { Assume.assumeTrue(whole.markSupported()); whole.mark(1024); int read = whole.read(); whole.reset(); int reread = whole.read(); assertEquals(read, reread); }
static PartitionDefinition readWritablePartition(BytesArray bytes) throws IOException { FastByteArrayInputStream in = new FastByteArrayInputStream(bytes); try { DataInputStream di = new DataInputStream(in); return new PartitionDefinition(di); } finally { in.close(); } }
@Test public void markSupported() throws Exception { assertTrue(whole.markSupported()); assertTrue(middle.markSupported()); }
/** * @return serialized bulk entry in byte array format */ public InputStream getEntryContents() { return new FastByteArrayInputStream(contents); }
@Override public String convert(BulkWriteFailure entry) { return String.format( "Dropping failed bulk entry (response [%s] from server) after [%s] attempts due to error [%s]:%n" + "Entry Contents:%n%s", entry.getResponseCode(), entry.getNumberOfAttempts(), entry.getException().getMessage(), ((FastByteArrayInputStream) entry.getEntryContents()).bytes().toString() ); } }
@Override protected InputStream openRead() throws FileNotFoundException { return new FastByteArrayInputStream(fileBytes); }
assertEquals(401, entry.getResponseCode()); return collector.retry(((FastByteArrayInputStream)entry.getEntryContents()).bytes().bytes()); } else if (attemptCount == 2) { assertEquals(2, entry.getNumberOfAttempts());
static PartitionDefinition readSerializablePartition(BytesArray bytes) throws IOException, ClassNotFoundException { FastByteArrayInputStream in = new FastByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(in); return (PartitionDefinition) ois.readObject(); }
@Override public String convert(DeserializationFailure entry) { return String.format( "Dropping malformed scroll search hit due to error [%s]:%nEntry Contents:%n%s", entry.getException().getMessage(), ((FastByteArrayInputStream) entry.getHitContents()).bytes().toString() ); } }
@SuppressWarnings("unchecked") public static <T extends Serializable> T deserializeFromBase64(String data) { if (!StringUtils.hasLength(data)) { return null; } byte[] rawData = DatatypeConverter.parseBase64Binary(data); ObjectInputStream ois = null; try { ois = new ObjectInputStream(new FastByteArrayInputStream(rawData)); Object o = ois.readObject(); return (T) o; } catch (ClassNotFoundException ex) { throw new EsHadoopIllegalStateException("cannot deserialize object", ex); } catch (IOException ex) { throw new EsHadoopSerializationException("cannot deserialize object", ex); } finally { close(ois); } }
@Override public String convert(DeserializationFailure entry) { return String.format( "Dropping malformed scroll search hit due to error [%s]:%nEntry Contents:%n%s", entry.getException().getMessage(), ((FastByteArrayInputStream) entry.getHitContents()).bytes().toString() ); } }
public Scroll read(InputStream content) throws IOException { Assert.notNull(content); //copy content BytesArray copy = IOUtils.asBytes(content); content = new FastByteArrayInputStream(copy); if (log.isTraceEnabled()) { log.trace("About to parse scroll content " + copy); } Parser parser = new JacksonJsonParser(content); try { return read(parser, copy); } finally { parser.close(); } }
@Override public String convert(DeserializationFailure entry) { return String.format( "Dropping malformed scroll search hit due to error [%s]:%nEntry Contents:%n%s", entry.getException().getMessage(), ((FastByteArrayInputStream) entry.getHitContents()).bytes().toString() ); } }
@Before public void setup() { BytesArray all = new BytesArray(new byte[]{1, 2, 3, 4, 5, 6}); BytesArray middleFour = new BytesArray(all.bytes, 1, 4); whole = new FastByteArrayInputStream(all); middle = new FastByteArrayInputStream(middleFour); }
@Override public String convert(BulkWriteFailure entry) { return String.format( "Dropping failed bulk entry (response [%s] from server) after [%s] attempts due to error [%s]:%n" + "Entry Contents:%n%s", entry.getResponseCode(), entry.getNumberOfAttempts(), entry.getException().getMessage(), ((FastByteArrayInputStream) entry.getEntryContents()).bytes().toString() ); } }
@Before public void before() throws Exception { InputStream in = new FastByteArrayInputStream(IOUtils.asBytes(getClass().getResourceAsStream("parser-test-nested.json"))); parser = new JacksonJsonParser(in); }
@Override public String convert(BulkWriteFailure entry) { return String.format( "Dropping failed bulk entry (response [%s] from server) after [%s] attempts due to error [%s]:%n" + "Entry Contents:%n%s", entry.getResponseCode(), entry.getNumberOfAttempts(), entry.getException().getMessage(), ((FastByteArrayInputStream) entry.getEntryContents()).bytes().toString() ); } }