當前位置: 首頁>>代碼示例>>Java>>正文


Java Json.newDocumentStream方法代碼示例

本文整理匯總了Java中org.ojai.json.Json.newDocumentStream方法的典型用法代碼示例。如果您正苦於以下問題:Java Json.newDocumentStream方法的具體用法?Java Json.newDocumentStream怎麽用?Java Json.newDocumentStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.ojai.json.Json的用法示例。


在下文中一共展示了Json.newDocumentStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testProjectChildParentAndChild

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testProjectChildParentAndChild() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("k.l.l1", "k", "k.l.l1");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.START_MAP, "k");
    assertMapEvent(r, EventType.START_MAP, "l");
    assertMapEvent(r, EventType.START_MAP, "l1");
    assertMapEvent(r, EventType.DOUBLE, "l2");
    assertMapEvent(r, EventType.END_MAP, "l1");
    assertMapEvent(r, EventType.DOUBLE, "l3");
    assertMapEvent(r, EventType.END_MAP, "l");
    assertMapEvent(r, EventType.END_MAP, "k");

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:26,代碼來源:TestDocumentReaderWithProjection.java

示例2: getDocument

import org.ojai.json.Json; //導入方法依賴的package包/類
@Override
public Document getDocument() {
  Preconditions.checkState(jsonGenerator.isClosed(), "The document has not been built.");

  if (b != null) {
    byte[] barray = b.getByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(barray);
    DocumentStream documentStream = Json.newDocumentStream(inputStream);
    Iterator<Document> iter = documentStream.iterator();
    if (iter.hasNext()) {
      Document r = iter.next();
      return r;
    }
  }
  return null;
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:17,代碼來源:JsonDocumentBuilder.java

示例3: testResources

import org.ojai.json.Json; //導入方法依賴的package包/類
private void testResources(String resource) throws IOException {
  try (InputStream testJson = getJsonStream(resource);
       DocumentStream stream = Json.newDocumentStream(testJson);
       InputStream testJson1 = getJsonStream(resource);
       DocumentStream stream1 = Json.newDocumentStream(testJson1);
       InputStream testJson2 = getJsonStream(resource);
       DocumentStream stream2 = Json.newDocumentStream(testJson2);) {
    for (Document document : stream) {
      assertEquals(document, document); // self comparison
    }
    // same documents extracted from different streams
    Iterator<Document> itr1 = stream1.iterator();
    Iterator<Document> itr2 = stream2.iterator();
    while (itr1.hasNext()) {
      assertEquals(itr1.next(), itr2.next());
    }
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:19,代碼來源:TestJsonDocumentEquals.java

示例4: testProjectScalarFieldAsContainer

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testProjectScalarFieldAsContainer() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("c.c1", "f.g.h[2]");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.START_MAP, "c");
    assertMapEvent(r, EventType.END_MAP, "c");

    assertMapEvent(r, EventType.START_MAP, "f");
    assertMapEvent(r, EventType.START_MAP, "g");
    assertMapEvent(r, EventType.START_ARRAY, "h");
    assertMapEvent(r, EventType.END_ARRAY, "h");
    assertMapEvent(r, EventType.END_MAP, "g");
    assertMapEvent(r, EventType.END_MAP, "f");

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:27,代碼來源:TestDocumentReaderWithProjection.java

示例5: testEmptyMissingField

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testEmptyMissingField() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("a.a1", "b.b1");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:17,代碼來源:TestDocumentReaderWithProjection.java

示例6: createJsonTables

import org.ojai.json.Json; //導入方法依賴的package包/類
public static void createJsonTables() throws IOException {
  admin = MapRDB.newAdmin();
  if (admin.tableExists(TMP_BUSINESS_TABLE)) {
    admin.deleteTable(TMP_BUSINESS_TABLE);
  }

  try (Table table = admin.createTable(TMP_BUSINESS_TABLE);
       InputStream in = getJsonStream("json/business.json");
       DocumentStream stream = Json.newDocumentStream(in)) {
    for (Document document : stream) {
      table.insert(document, "business_id");
    }
    table.flush();
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:16,代碼來源:MaprDBTestsSuite.java

示例7: initialize

import org.ojai.json.Json; //導入方法依賴的package包/類
@Override
public void initialize(InputSplit arg0, TaskAttemptContext taskContext)
    throws IOException, InterruptedException {

  documentStream = null;
  it = null;
  documentCount = 0;
  key = new LongWritable();
  document = null;
  currentPos = 0;

  /* get the split */
  FileSplit split = (FileSplit) arg0;

  /* get configuration object */
  Configuration job = taskContext.getConfiguration();

  /* initialize file /input stream */
  final Path path = split.getPath();
  FileSystem fs = path.getFileSystem(job);
  inputStream = fs.open(path);

  CompressionCodec codec = new CompressionCodecFactory(job).getCodec(path);

  if (codec != null) {
    decompressor = CodecPool.getDecompressor(codec);
    inputStream = codec.createInputStream(inputStream, decompressor);
  }

  start = split.getStart();
  end = start + split.getLength();

  /* Initialize a stream reader so that it can read multiple documents from */
  /* the file */

  documentStream = (JsonDocumentStream)Json.newDocumentStream(inputStream);
  it = documentStream.iterator();

}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:40,代碼來源:JSONFileRecordReader.java

示例8: testFetchAndParseJsonDocumentStream

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testFetchAndParseJsonDocumentStream() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/business.json");
       DocumentStream stream = Json.newDocumentStream(in)) {

    int documentCount = 0;
    for (DocumentReader reader : stream.documentReaders()) {
      documentCount++;
      testDocumentReaderFromIterator(reader);
    }
    assertEquals(5, documentCount);
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:14,代碼來源:TestJsonDocumentStream.java

示例9: testProjectEmptyMapAndArray

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testProjectEmptyMapAndArray() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("f.g.i.i1.i2.i3.i4.i5", "f.g.i.i1.i2.i3.i4.i6");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.START_MAP, "f");
    assertMapEvent(r, EventType.START_MAP, "g");
    assertMapEvent(r, EventType.START_MAP, "i");
    assertMapEvent(r, EventType.START_MAP, "i1");
    assertMapEvent(r, EventType.START_MAP, "i2");
    assertMapEvent(r, EventType.START_MAP, "i3");
    assertMapEvent(r, EventType.START_MAP, "i4");
    assertMapEvent(r, EventType.START_ARRAY, "i5");
    // []
    assertMapEvent(r, EventType.END_ARRAY, "i5");
    assertMapEvent(r, EventType.START_MAP, "i6");
    // {}
    assertMapEvent(r, EventType.END_MAP, "i6");
    assertMapEvent(r, EventType.END_MAP, "i4");
    assertMapEvent(r, EventType.END_MAP, "i3");
    assertMapEvent(r, EventType.END_MAP, "i2");
    assertMapEvent(r, EventType.END_MAP, "i1");
    assertMapEvent(r, EventType.END_MAP, "i");
    assertMapEvent(r, EventType.END_MAP, "g");
    assertMapEvent(r, EventType.END_MAP, "f");

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:38,代碼來源:TestDocumentReaderWithProjection.java

示例10: testFetchAndParsePartiallyJsonDocumentStream

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testFetchAndParsePartiallyJsonDocumentStream() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/business.json");
       DocumentStream stream = Json.newDocumentStream(in)) {

    int documentCount = 0;
    for (DocumentReader reader : stream.documentReaders()) {
      documentCount++;
      logger.debug("First event in the DocumentReader: " + reader.next());
    }
    assertEquals(5, documentCount);
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:14,代碼來源:TestJsonDocumentStream.java

示例11: testProjectEmptyMap

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testProjectEmptyMap() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("f.g.i.i1.i2.i3.i4.i6");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.START_MAP, "f");
    assertMapEvent(r, EventType.START_MAP, "g");
    assertMapEvent(r, EventType.START_MAP, "i");
    assertMapEvent(r, EventType.START_MAP, "i1");
    assertMapEvent(r, EventType.START_MAP, "i2");
    assertMapEvent(r, EventType.START_MAP, "i3");
    assertMapEvent(r, EventType.START_MAP, "i4");
    assertMapEvent(r, EventType.START_MAP, "i6");
    // {}
    assertMapEvent(r, EventType.END_MAP, "i6");
    assertMapEvent(r, EventType.END_MAP, "i4");
    assertMapEvent(r, EventType.END_MAP, "i3");
    assertMapEvent(r, EventType.END_MAP, "i2");
    assertMapEvent(r, EventType.END_MAP, "i1");
    assertMapEvent(r, EventType.END_MAP, "i");
    assertMapEvent(r, EventType.END_MAP, "g");
    assertMapEvent(r, EventType.END_MAP, "f");

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:35,代碼來源:TestDocumentReaderWithProjection.java

示例12: testHybridFormat

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testHybridFormat() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/hybridFormat.json");
      DocumentStream stream = Json.newDocumentStream(in)) {
    int documentCount = getDocumentCount(stream.documentReaders());
    assertEquals(6, documentCount);
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:9,代碼來源:TestJsonDocumentStreamFormat.java

示例13: testDocumentListener

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testDocumentListener() throws IOException {
  final Document status = Json.newDocument();

  try (InputStream in = getJsonStream("org/ojai/test/data/multidocument.json");
      DocumentStream stream = Json.newDocumentStream(in)) {
    stream.streamTo(new DocumentListener() {
      int documentProcessed = 0;
      @Override
      public boolean documentArrived(Document document) {
        documentProcessed++;
        status.set("documentArrived", true);
        logger.info("Document arrived: %s", document.asJsonString());
        if ("id3".equals(document.getString("business_id"))) {
          return false;
        } else {
          return true;
        }
      }

      @Override
      public void failed(Exception e) {
        status.set("failed", true);
      }

      @Override
      public void eos() {
        status.set("eos", true);
        assertEquals(3, documentProcessed);
      }
    });

    assertEquals(true, status.getBoolean("documentArrived"));
    assertNull(status.getBooleanObj("failed"));
    assertEquals(true, status.getBoolean("eos"));
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:38,代碼來源:TestJsonDocumentStream.java

示例14: testParseStreamWithManyMiscDocs

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testParseStreamWithManyMiscDocs() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/manymiscdocs.json");
      DocumentStream stream = Json.newDocumentStream(in)) {

    int documentCount = 0;
    for (DocumentReader reader : stream.documentReaders()) {
      documentCount++;
      if (documentCount == 1) {
        validateDocumentReaderOne(reader);
      }
      if (documentCount == 2) {
        validateDocumentReaderTwo(reader);
      }
      if (documentCount == 3){
        validateDocumentReaderThree(reader);
      }
      if (documentCount == 5) {
        validateMapDocBetweenArrays(reader);
      }
      if (documentCount == 6) {
        validateDocumentReaderFive(reader);
      }
    }
    assertEquals(7, documentCount);
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:28,代碼來源:TestJsonDocumentStreamFormat.java

示例15: testJsonSerialization

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testJsonSerialization() throws Exception {
  try (InputStream in = getJsonStream("multidocument.json");
       DocumentStream stream = Json.newDocumentStream(in)) {
    for (DocumentReader reader : stream.documentReaders()) {
      DocumentBuilder builder = Json.newDocumentBuilder();
      Documents.writeReaderToBuilder(reader, builder);
      logger.info(builder.toString());
    }
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:12,代碼來源:TestJsonUtil.java


注:本文中的org.ojai.json.Json.newDocumentStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。