当前位置: 首页>>代码示例>>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;未经允许,请勿转载。