本文整理汇总了Java中org.apache.avro.io.parsing.Symbol类的典型用法代码示例。如果您正苦于以下问题:Java Symbol类的具体用法?Java Symbol怎么用?Java Symbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Symbol类属于org.apache.avro.io.parsing包,在下文中一共展示了Symbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readString
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public String readString() throws IOException {
advance(Symbol.STRING);
if (parser.topSymbol() == Symbol.MAP_KEY_MARKER) {
parser.advance(Symbol.MAP_KEY_MARKER);
if (in.getCurrentToken() != JsonToken.FIELD_NAME) {
throw error("map-key");
}
} else {
if (in.getCurrentToken() != JsonToken.VALUE_STRING) {
throw error("string");
}
}
String result = in.getText();
in.nextToken();
return result;
}
示例2: readEnum
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public int readEnum() throws IOException {
advance(Symbol.ENUM);
Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
in.getText();
int n = top.findLabel(in.getText());
if (n >= 0) {
in.nextToken();
return n;
}
throw new AvroTypeException("Unknown symbol in enum " + in.getText());
} else {
throw error("fixed");
}
}
示例3: readIndex
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public int readIndex() throws IOException {
advance(Symbol.UNION);
Symbol.Alternative a = (Symbol.Alternative) parser.popSymbol();
String label;
if (in.getCurrentToken() == JsonToken.VALUE_NULL) {
label = "null";
} else if (in.getCurrentToken() == JsonToken.START_OBJECT &&
in.nextToken() == JsonToken.FIELD_NAME) {
label = in.getText();
in.nextToken();
parser.pushSymbol(Symbol.UNION_END);
} else {
throw error("start-union");
}
int n = a.findLabel(label);
if (n < 0)
throw new AvroTypeException("Unknown union branch " + label);
parser.pushSymbol(a.getSymbol(n));
return n;
}
示例4: writeIndex
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public void writeIndex(int unionIndex) throws IOException {
parser.advance(Symbol.UNION);
Symbol.Alternative top = (Symbol.Alternative) parser.popSymbol();
Symbol symbol = top.getSymbol(unionIndex);
if(symbol != Symbol.NULL && isUnionOfNullWithSomething(top)){
// parser.pushSymbol(Symbol.UNION_END);
parser.pushSymbol(symbol);
return;
}
if (symbol != Symbol.NULL) {
out.writeStartObject();
out.writeFieldName(top.getLabel(unionIndex));
parser.pushSymbol(Symbol.UNION_END);
}
parser.pushSymbol(symbol);
}
示例5: readString
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public String readString() throws IOException {
advance(Symbol.STRING);
if (parser.topSymbol() == Symbol.MAP_KEY_MARKER) {
parser.advance(Symbol.MAP_KEY_MARKER);
if (in.getCurrentToken() != JsonToken.FIELD_NAME) {
throw error("map-key");
}
} else {
if (in.getCurrentToken() != JsonToken.VALUE_STRING) {
throw error("string");
}
}
String result = in.getText();
in.nextToken();
return result;
}
示例6: readEnum
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public int readEnum() throws IOException {
advance(Symbol.ENUM);
Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
in.getText();
int n = top.findLabel(in.getText());
if (n >= 0) {
in.nextToken();
return n;
}
throw new AvroTypeException("Unknown symbol in enum " + in.getText());
} else {
throw error("fixed");
}
}
示例7: readBoolean
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public boolean readBoolean() throws IOException {
advance(Symbol.BOOLEAN);
JsonToken t = in.getCurrentToken();
if (t == JsonToken.VALUE_TRUE || t == JsonToken.VALUE_FALSE) {
in.nextToken();
return t == JsonToken.VALUE_TRUE;
} else {
String s = in.getText();
if(s.equals("false") || s.equals("FALSE") || s.equals("0")) {
in.nextToken();
return false;
}
else if(s.equals("true") || s.equals("TRUE") || s.equals("1")) {
in.nextToken();
return true;
}
throw error("boolean");
}
}
示例8: readInt
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public int readInt() throws IOException {
advance(Symbol.INT);
if (in.getCurrentToken().isNumeric()) {
int result = in.getIntValue();
in.nextToken();
return result;
} else {
try {
String s = in.getText();
in.nextToken();
return Integer.parseInt(s);
}
catch(Exception e) {
throw error("int (" + e.getMessage() + ")");
}
}
}
示例9: readLong
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public long readLong() throws IOException {
advance(Symbol.LONG);
if (in.getCurrentToken().isNumeric()) {
long result = in.getLongValue();
in.nextToken();
return result;
} else {
try {
String s = in.getText();
in.nextToken();
return Long.parseLong(s);
}
catch(Exception e) {
throw error("long (" + e.getMessage() + ")");
}
}
}
示例10: readString
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public String readString() throws IOException {
advance(Symbol.STRING);
if (parser.topSymbol() == Symbol.MAP_KEY_MARKER) {
parser.advance(Symbol.MAP_KEY_MARKER);
if (in.getCurrentToken() != JsonToken.FIELD_NAME) {
throw error("map-key");
}
} else {
if (in.getCurrentToken() != JsonToken.VALUE_STRING) {
throw error("string");
}
}
String result = in.getText();
in.nextToken();
return result;
}
示例11: readEnum
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public int readEnum() throws IOException {
advance(Symbol.ENUM);
Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
in.getText();
int n = top.findLabel(in.getText());
if (n >= 0) {
in.nextToken();
return n;
}
throw new AvroTypeException("Unknown symbol in enum " + in.getText());
} else {
throw error("fixed");
}
}
示例12: hasErrorSymbol
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
/**
* Determine if the symbol tree has an error symbol in it. This would indicate
* that the two schemas are not compatible.
*
* @param rootSymbol
* The root symbol to traverse from to look for an error symbol.
* @return true if an error symbol exists in the tree.
*/
private static boolean hasErrorSymbol(Symbol rootSymbol) {
if (rootSymbol.production == null) {
return false;
}
for (Symbol s : rootSymbol.production) {
if (s == rootSymbol) {
continue;
}
if (s.getClass().equals(Symbol.ErrorAction.class)) {
return true;
} else {
if (s.production != null) {
for (Symbol subSymbol : s.production) {
if (hasErrorSymbol(subSymbol)) {
return true;
}
}
}
}
}
return false;
}
示例13: hasErrors
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
/**
* Returns true if the Parser contains any Error symbol, indicating that it may fail
* for some inputs.
*/
private static boolean hasErrors(Symbol symbol) {
switch(symbol.kind) {
case ALTERNATIVE:
return hasErrors(((Symbol.Alternative) symbol).symbols);
case EXPLICIT_ACTION:
return false;
case IMPLICIT_ACTION:
return symbol instanceof Symbol.ErrorAction;
case REPEATER:
Symbol.Repeater r = (Symbol.Repeater) symbol;
return hasErrors(r.end) || hasErrors(r.production);
case ROOT:
return hasErrors(Arrays.copyOfRange(symbol.production, 1, symbol.production.length));
case SEQUENCE:
return hasErrors(symbol.production);
case TERMINAL:
return false;
default:
throw new RuntimeException("unknown symbol kind: " + symbol.kind);
}
}
示例14: readNull
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public void readNull() throws IOException {
advance(Symbol.NULL);
if (in.getCurrentToken() == JsonToken.VALUE_NULL) {
in.nextToken();
} else {
throw error("null");
}
}
示例15: readBoolean
import org.apache.avro.io.parsing.Symbol; //导入依赖的package包/类
@Override
public boolean readBoolean() throws IOException {
advance(Symbol.BOOLEAN);
JsonToken t = in.getCurrentToken();
if (t == JsonToken.VALUE_TRUE || t == JsonToken.VALUE_FALSE) {
in.nextToken();
return t == JsonToken.VALUE_TRUE;
} else {
throw error("boolean");
}
}