本文整理汇总了Java中org.codehaus.jackson.JsonParser.skipChildren方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.skipChildren方法的具体用法?Java JsonParser.skipChildren怎么用?Java JsonParser.skipChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.JsonParser
的用法示例。
在下文中一共展示了JsonParser.skipChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSkipChildren
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
/**
* @param jParser
* @param fieldname1
* @throws IOException
* @throws JsonParseException
*/
public static void findSkipChildren(JsonParser jParser) throws IOException, JsonParseException {
while (jParser.nextToken() != JsonToken.END_OBJECT) {
String fieldname = jParser.getCurrentName();
if (fieldname != null && fieldname.contains("children")) {
// System.out.println("Skipping children");
jParser.nextToken(); // current token is "[", move next
jParser.skipChildren();
}
}
}
示例2: findDiffNode
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private static void findDiffNode(JsonParser jParser) throws JsonParseException, IOException {
String nodeName = null;
while (jParser.nextToken() != JsonToken.END_ARRAY) {
String fieldname1 = jParser.getCurrentName();
if ("name".equals(fieldname1)) {
jParser.nextToken();
nodeName = jParser.getText();
}
if ("hits".equals(fieldname1)) {
jParser.nextToken(); //the [
jParser.skipChildren();
System.out.println("Node " + nodeName + " hit");
}
if ("diff".equals(fieldname1)) {
jParser.nextToken();
String diff = jParser.getText();
if(!"SameStyle".equals(diff)) {
System.out.println("found diff node " + nodeName + ":" + diff);
if(nodeName.contains("Properties")) {
findDiffProperties(jParser);
}
else {
findDiffChildren(jParser);
}
}
else {
// System.out.println("Skipping node " + nodeName);
findSkipChildren(jParser);
}
}
if (fieldname1 != null && fieldname1.contains("children")) {
// System.out.println("Skipping children of " + nodeName);
jParser.nextToken(); // current token is "[", move next
jParser.skipChildren();
}
}
}
示例3: deserialize
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public Object deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Object paramObject)
throws IOException, JsonProcessingException
{
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
if (localJsonToken == JsonToken.START_OBJECT)
localJsonToken = paramJsonParser.nextToken();
if (localJsonToken == JsonToken.FIELD_NAME)
{
String str = paramJsonParser.getCurrentName();
SettableBeanProperty localSettableBeanProperty = this._beanProperties.find(str);
paramJsonParser.nextToken();
if (localSettableBeanProperty != null);
while (true)
{
try
{
localSettableBeanProperty.deserializeAndSet(paramJsonParser, paramDeserializationContext, paramObject);
localJsonToken = paramJsonParser.nextToken();
}
catch (Exception localException)
{
wrapAndThrow(localException, paramObject, str, paramDeserializationContext);
continue;
}
if ((this._ignorableProps != null) && (this._ignorableProps.contains(str)))
{
paramJsonParser.skipChildren();
continue;
}
if (this._anySetter != null)
{
this._anySetter.deserializeAndSet(paramJsonParser, paramDeserializationContext, paramObject, str);
continue;
}
handleUnknownProperty(paramJsonParser, paramDeserializationContext, paramObject, str);
}
}
return paramObject;
}
示例4: handleUnknownProperty
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
protected void handleUnknownProperty(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Object paramObject, String paramString)
throws IOException, JsonProcessingException
{
if ((this._ignoreAllUnknown) || ((this._ignorableProps != null) && (this._ignorableProps.contains(paramString))))
{
paramJsonParser.skipChildren();
return;
}
super.handleUnknownProperty(paramJsonParser, paramDeserializationContext, paramObject, paramString);
}
示例5: handleUnknownProperty
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
protected void handleUnknownProperty(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Object paramObject, String paramString)
throws IOException, JsonProcessingException
{
if (paramObject == null)
paramObject = getValueClass();
if (paramDeserializationContext.handleUnknownProperty(paramJsonParser, this, paramObject, paramString))
return;
reportUnknownProperty(paramDeserializationContext, paramObject, paramString);
paramJsonParser.skipChildren();
}
示例6: testStreamingJSON
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Test
public void testStreamingJSON() throws Exception {
// Test scanning particular columns with limit.
StringBuilder builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_LIMIT + "=20");
Response response = client.get("/" + TABLE + builder.toString(),
Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
ObjectMapper mapper = new JacksonProvider()
.locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
CellSetModel model = mapper.readValue(response.getStream(), CellSetModel.class);
int count = TestScannerResource.countCellSet(model);
assertEquals(20, count);
checkRowsNotNull(model);
//Test scanning with no limit.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_2);
response = client.get("/" + TABLE + builder.toString(),
Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
model = mapper.readValue(response.getStream(), CellSetModel.class);
count = TestScannerResource.countCellSet(model);
assertEquals(expectedRows2, count);
checkRowsNotNull(model);
//Test with start row and end row.
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aay");
response = client.get("/" + TABLE + builder.toString(),
Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
count = 0;
JsonFactory jfactory = new JsonFactory(mapper);
JsonParser jParser = jfactory.createJsonParser(response.getStream());
boolean found = false;
while (jParser.nextToken() != JsonToken.END_OBJECT) {
if(jParser.getCurrentToken() == JsonToken.START_OBJECT && found) {
RowModel row = jParser.readValueAs(RowModel.class);
assertNotNull(row.getKey());
for (int i = 0; i < row.getCells().size(); i++) {
if (count == 0) {
assertEquals("aaa", Bytes.toString(row.getKey()));
}
if (count == 23) {
assertEquals("aax", Bytes.toString(row.getKey()));
}
count++;
}
jParser.skipChildren();
} else {
found = jParser.getCurrentToken() == JsonToken.START_ARRAY;
}
}
assertEquals(24, count);
}
示例7: importSorted
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
IPartitioner partitioner) throws IOException
{
int importedKeys = 0; // already imported keys count
long start = System.nanoTime();
JsonParser parser = getParser(jsonFile);
if (keyCountToImport == null)
{
keyCountToImport = 0;
System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
parser.skipChildren();
if (parser.getCurrentToken() == JsonToken.END_ARRAY)
break;
keyCountToImport++;
}
}
System.out.printf("Importing %s keys...%n", keyCountToImport);
parser = getParser(jsonFile); // renewing parser
SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport, ActiveRepairService.UNREPAIRED_SSTABLE);
int lineNumber = 1;
DecoratedKey prevStoredKey = null;
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
String key = parser.getCurrentName();
Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
DecoratedKey currentKey = partitioner.decorateKey(getKeyValidator(columnFamily).fromString((String) row.get("key")));
if (row.containsKey("metadata"))
parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);
addColumnsToCF((List<?>) row.get("cells"), columnFamily);
if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
{
System.err
.printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
lineNumber, key);
return -1;
}
// saving decorated key
writer.append(currentKey, columnFamily);
columnFamily.clear();
prevStoredKey = currentKey;
importedKeys++;
lineNumber++;
long current = System.nanoTime();
if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
{
System.out.printf("Currently imported %d keys.%n", importedKeys);
start = current;
}
if (keyCountToImport == importedKeys)
break;
}
writer.closeAndOpenReader();
return importedKeys;
}
示例8: importSorted
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
IPartitioner<?> partitioner) throws IOException
{
int importedKeys = 0; // already imported keys count
long start = System.nanoTime();
JsonParser parser = getParser(jsonFile);
if (keyCountToImport == null)
{
keyCountToImport = 0;
System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
parser.skipChildren();
if (parser.getCurrentToken() == JsonToken.END_ARRAY)
break;
keyCountToImport++;
}
}
System.out.printf("Importing %s keys...%n", keyCountToImport);
parser = getParser(jsonFile); // renewing parser
SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport);
int lineNumber = 1;
DecoratedKey prevStoredKey = null;
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
String key = parser.getCurrentName();
Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
DecoratedKey currentKey = partitioner.decorateKey(hexToBytes((String) row.get("key")));
if (row.containsKey("metadata"))
parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);
if (columnFamily.getType() == ColumnFamilyType.Super && oldSCFormat)
addToSuperCF((Map<?, ?>)row.get("columns"), columnFamily);
else
addToStandardCF((List<?>)row.get("columns"), columnFamily);
if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
{
System.err
.printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
lineNumber, key);
return -1;
}
// saving decorated key
writer.append(currentKey, columnFamily);
columnFamily.clear();
prevStoredKey = currentKey;
importedKeys++;
lineNumber++;
long current = System.nanoTime();
if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
{
System.out.printf("Currently imported %d keys.%n", importedKeys);
start = current;
}
if (keyCountToImport == importedKeys)
break;
}
writer.closeAndOpenReader();
return importedKeys;
}
示例9: parseObjectIntoTuple
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
/**
* Given a JsonParser positioned at the beginning of an object,
* parse that object and load its fields into the given tuple.
* Ignore fields that are not in the schemaMap and set any fields
* that are missing or threw an exception while parsing to null.
*
* The full text of the record is provided 1) to allow for more informative
* error messages, and 2) to allow JSON objects/arrays to be type coerced
* into bytearrays or chararrays properly if the schema requests it.
*
* Returns false if and END_ARRAY token is found. This indicates that the
* calling method is iterating through the objects in an array/bag and
* ought to stop.
*/
public static boolean parseObjectIntoTuple(String text, JsonParser p,
Map<String, ResourceFieldSchema> schemaMap,
Map<String, Integer> schemaPositionMap,
Tuple t)
throws IOException {
JsonToken tok = p.getCurrentToken();
if (tok == JsonToken.END_ARRAY)
return false;
if (tok != JsonToken.START_OBJECT) {
throw new JsonParseException("No start of object found", p.getCurrentLocation());
}
while((tok = p.nextToken()) != JsonToken.END_OBJECT) {
if (tok != JsonToken.FIELD_NAME)
throw new JsonParseException("No field name found", p.getCurrentLocation());
String fieldName = escapeFieldName(p.getText());
if (schemaMap.containsKey(fieldName)) {
ResourceFieldSchema field = schemaMap.get(fieldName);
int fieldNum = schemaPositionMap.get(fieldName).intValue();
try {
p.nextToken(); // move to val
t.set(fieldNum, readField(text, p, field));
} catch (Exception e) {
log.error("Exception when parsing field \"" + fieldName + "\" " +
"in record " + text + ": " + e.toString());
t.set(fieldNum, null);
p.skipChildren(); // if the error happened at a start object/array token
// skip its children and move onto the next token
// at this level
}
} else {
// if the key is not in the schema
// skip the value/object and move on
tok = p.nextToken();
p.skipChildren();
}
}
return true;
}
示例10: readFieldAsString
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public static String readFieldAsString(String text,
JsonParser p,
ResourceFieldSchema field)
throws IOException {
JsonToken tok = p.getCurrentToken();
if (tok == JsonToken.VALUE_NULL) return null;
if (tok.isScalarValue()) {
return p.getText();
} else {
JsonToken start, end;
int startPos, endPos, nesting;
if (tok == JsonToken.START_OBJECT) {
start = JsonToken.START_OBJECT;
end = JsonToken.END_OBJECT;
} else if (tok == JsonToken.START_ARRAY) {
start = JsonToken.START_ARRAY;
end = JsonToken.END_ARRAY;
} else {
// Should never happen
throw new IllegalArgumentException(
"Bad bytearray/chararray field: expected scalar value or start object/array token, but found " + tok.asString());
}
// skip to the end of this object/array
// The parser's reported column number depends on whitespace
// and other weirdness I don't quite get, so the simplest way
// that I could find to handle nested structures is to use
// this "rewind" method
p.skipChildren();
endPos = p.getCurrentLocation().getColumnNr();
startPos = endPos;
if (end == JsonToken.END_OBJECT) {
while (text.charAt(endPos) != '}' && endPos > 0) endPos--;
nesting = 1;
startPos = endPos;
while (nesting > 0 && startPos > 0) {
startPos--;
if (text.charAt(startPos) == '}')
nesting++;
else if (text.charAt(startPos) == '{')
nesting--;
}
} else if (end == JsonToken.END_ARRAY) {
while (text.charAt(endPos) != ']' && endPos > 0) endPos--;
nesting = 1;
startPos = endPos;
while (nesting > 0 && startPos > 0) {
startPos--;
if (text.charAt(startPos) == ']')
nesting++;
else if (text.charAt(startPos) == '[')
nesting--;
}
}
return text.substring(startPos, endPos + 1);
}
}
示例11: importSorted
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
IPartitioner<?> partitioner) throws IOException
{
int importedKeys = 0; // already imported keys count
long start = System.nanoTime();
JsonParser parser = getParser(jsonFile);
if (keyCountToImport == null)
{
keyCountToImport = 0;
System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
parser.skipChildren();
if (parser.getCurrentToken() == JsonToken.END_ARRAY)
break;
keyCountToImport++;
}
}
System.out.printf("Importing %s keys...%n", keyCountToImport);
parser = getParser(jsonFile); // renewing parser
SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport, ActiveRepairService.UNREPAIRED_SSTABLE);
int lineNumber = 1;
DecoratedKey prevStoredKey = null;
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
String key = parser.getCurrentName();
Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
DecoratedKey currentKey = partitioner.decorateKey(getKeyValidator(columnFamily).fromString((String) row.get("key")));
if (row.containsKey("metadata"))
parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);
addColumnsToCF((List<?>) row.get("cells"), columnFamily);
if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
{
System.err
.printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
lineNumber, key);
return -1;
}
// saving decorated key
writer.append(currentKey, columnFamily);
columnFamily.clear();
prevStoredKey = currentKey;
importedKeys++;
lineNumber++;
long current = System.nanoTime();
if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
{
System.out.printf("Currently imported %d keys.%n", importedKeys);
start = current;
}
if (keyCountToImport == importedKeys)
break;
}
writer.closeAndOpenReader();
return importedKeys;
}
示例12: importSorted
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
IPartitioner<?> partitioner) throws IOException
{
int importedKeys = 0; // already imported keys count
long start = System.currentTimeMillis();
JsonParser parser = getParser(jsonFile);
if (keyCountToImport == null)
{
keyCountToImport = 0;
System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
parser.skipChildren();
if (parser.getCurrentToken() == JsonToken.END_ARRAY)
break;
keyCountToImport++;
}
}
System.out.printf("Importing %s keys...%n", keyCountToImport);
parser = getParser(jsonFile); // renewing parser
SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport);
int lineNumber = 1;
DecoratedKey prevStoredKey = null;
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
String key = parser.getCurrentName();
Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
DecoratedKey currentKey = partitioner.decorateKey(hexToBytes((String) row.get("key")));
if (row.containsKey("metadata"))
parseMeta((Map<?, ?>) row.get("metadata"), columnFamily);
if (columnFamily.getType() == ColumnFamilyType.Super)
addToSuperCF((Map<?, ?>)row.get("columns"), columnFamily);
else
addToStandardCF((List<?>)row.get("columns"), columnFamily);
if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
{
System.err
.printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
lineNumber, key);
return -1;
}
// saving decorated key
writer.append(currentKey, columnFamily);
columnFamily.clear();
prevStoredKey = currentKey;
importedKeys++;
lineNumber++;
long current = System.currentTimeMillis();
if (current - start >= 5000) // 5 secs.
{
System.out.printf("Currently imported %d keys.%n", importedKeys);
start = current;
}
if (keyCountToImport == importedKeys)
break;
}
writer.closeAndOpenReader();
return importedKeys;
}
示例13: deserializeFromObject
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public Object deserializeFromObject(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
Object localObject;
if (this._defaultConstructor == null)
if (this._propertyBasedCreator != null)
localObject = _deserializeUsingPropertyBased(paramJsonParser, paramDeserializationContext);
do
{
return localObject;
if (this._delegatingCreator != null)
return this._delegatingCreator.deserialize(paramJsonParser, paramDeserializationContext);
if (this._beanType.isAbstract())
throw JsonMappingException.from(paramJsonParser, "Can not instantiate abstract type " + this._beanType + " (need to add/enable type information?)");
throw JsonMappingException.from(paramJsonParser, "No suitable constructor found for type " + this._beanType + ": can not instantiate from JSON object (need to add/enable type information?)");
localObject = constructDefaultInstance();
}
while (paramJsonParser.getCurrentToken() == JsonToken.END_OBJECT);
String str = paramJsonParser.getCurrentName();
paramJsonParser.nextToken();
SettableBeanProperty localSettableBeanProperty = this._beanProperties.find(str);
if (localSettableBeanProperty != null);
while (true)
{
try
{
localSettableBeanProperty.deserializeAndSet(paramJsonParser, paramDeserializationContext, localObject);
paramJsonParser.nextToken();
}
catch (Exception localException2)
{
wrapAndThrow(localException2, localObject, str, paramDeserializationContext);
continue;
}
if ((this._ignorableProps != null) && (this._ignorableProps.contains(str)))
{
paramJsonParser.skipChildren();
continue;
}
if (this._anySetter != null)
{
try
{
this._anySetter.deserializeAndSet(paramJsonParser, paramDeserializationContext, localObject, str);
}
catch (Exception localException1)
{
wrapAndThrow(localException1, localObject, str, paramDeserializationContext);
}
continue;
}
handleUnknownProperty(paramJsonParser, paramDeserializationContext, localObject, str);
}
}
示例14: importSorted
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath,
IPartitioner<?> partitioner) throws IOException
{
int importedKeys = 0; // already imported keys count
long start = System.nanoTime();
JsonParser parser = getParser(jsonFile);
if (keyCountToImport == null)
{
keyCountToImport = 0;
System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
parser.skipChildren();
if (parser.getCurrentToken() == JsonToken.END_ARRAY)
break;
keyCountToImport++;
}
}
System.out.printf("Importing %s keys...%n", keyCountToImport);
parser = getParser(jsonFile); // renewing parser
SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport, ActiveRepairService.UNREPAIRED_SSTABLE);
int lineNumber = 1;
DecoratedKey prevStoredKey = null;
parser.nextToken(); // START_ARRAY
while (parser.nextToken() != null)
{
String key = parser.getCurrentName();
Map<?, ?> row = parser.readValueAs(new TypeReference<Map<?, ?>>(){});
DecoratedKey currentKey = partitioner.decorateKey(hexToBytes((String) row.get("key")));
if (row.containsKey("metadata"))
parseMeta((Map<?, ?>) row.get("metadata"), columnFamily, null);
if (columnFamily.getType() == ColumnFamilyType.Super && oldSCFormat)
addToSuperCF((Map<?, ?>)row.get("columns"), columnFamily);
else
addToStandardCF((List<?>)row.get("columns"), columnFamily);
if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1)
{
System.err
.printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n",
lineNumber, key);
return -1;
}
// saving decorated key
writer.append(currentKey, columnFamily);
columnFamily.clear();
prevStoredKey = currentKey;
importedKeys++;
lineNumber++;
long current = System.nanoTime();
if (TimeUnit.NANOSECONDS.toSeconds(current - start) >= 5) // 5 secs.
{
System.out.printf("Currently imported %d keys.%n", importedKeys);
start = current;
}
if (keyCountToImport == importedKeys)
break;
}
writer.closeAndOpenReader();
return importedKeys;
}
示例15: parseBackendResponse
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private static BackendResponse parseBackendResponse(JsonParser parser) throws IOException {
try {
// Sanity check: verify that we got "Json Object":
if (parser.nextToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected data to start with an Object");
}
long responseKey = 0;
int delay = 0;
int numItems = 0;
int itemSize = 0;
String[] items = null;
JsonToken current;
while (parser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = parser.getCurrentName();
// advance
current = parser.nextToken();
if (fieldName.equals("responseKey")) {
responseKey = parser.getLongValue();
} else if (fieldName.equals("delay")) {
delay = parser.getIntValue();
} else if (fieldName.equals("itemSize")) {
itemSize = parser.getIntValue();
} else if (fieldName.equals("numItems")) {
numItems = parser.getIntValue();
} else if (fieldName.equals("items")) {
// expect numItems to be populated before hitting this
if (numItems == 0) {
throw new IllegalStateException("Expected numItems > 0");
}
items = new String[numItems];
if (current == JsonToken.START_ARRAY) {
int j = 0;
// For each of the records in the array
while (parser.nextToken() != JsonToken.END_ARRAY) {
items[j++] = parser.getText();
}
} else {
// System.out.println("Error: items should be an array: skipping.");
parser.skipChildren();
}
}
}
return new BackendResponse(responseKey, delay, numItems, itemSize, items);
} finally {
parser.close();
}
}