本文整理汇总了Java中org.yaml.snakeyaml.reader.StreamReader类的典型用法代码示例。如果您正苦于以下问题:Java StreamReader类的具体用法?Java StreamReader怎么用?Java StreamReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamReader类属于org.yaml.snakeyaml.reader包,在下文中一共展示了StreamReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canonicalParse
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
protected List<Event> canonicalParse(InputStream input2) throws IOException {
StreamReader reader = new StreamReader(new UnicodeReader(input2));
StringBuilder buffer = new StringBuilder();
while (reader.peek() != '\0') {
buffer.append(reader.peek());
reader.forward();
}
CanonicalParser parser = new CanonicalParser(buffer.toString());
List<Event> result = new ArrayList<Event>();
while (parser.peekEvent() != null) {
result.add(parser.getEvent());
}
input2.close();
return result;
}
示例2: parse
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
/**
* Parse a YAML stream and produce parsing events.
*
* @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
* @param yaml
* YAML document(s)
* @return parsed events
*/
public Iterable<Event> parse(Reader yaml) {
final Parser parser = new ParserImpl(new StreamReader(yaml));
Iterator<Event> result = new Iterator<Event>() {
public boolean hasNext() {
return parser.peekEvent() != null;
}
public Event next() {
return parser.getEvent();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new EventIterable(result);
}
示例3: composeAll
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
/**
* Parse all YAML documents in a stream and produce corresponding
* representation trees.
*
* @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
* @param yaml
* stream of YAML documents
* @return parsed root Nodes for all the specified YAML documents
*/
public Iterable<Node> composeAll(Reader yaml) {
final Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
constructor.setComposer(composer);
Iterator<Node> result = new Iterator<Node>() {
public boolean hasNext() {
return composer.checkNode();
}
public Node next() {
return composer.getNode();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new NodeIterable(result);
}
示例4: representData
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
public Node representData(Object data) {
Tag tag = Tag.STR;
Character style = null;
String value = data.toString();
if (StreamReader.NON_PRINTABLE.matcher(value).find()) {
tag = Tag.BINARY;
char[] binary;
try {
binary = Base64Coder.encode(value.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new YAMLException(e);
}
value = String.valueOf(binary);
style = '|';
}
// if no other scalar style is explicitly set, use literal style for
// multiline scalars
if (defaultScalarStyle == null && MULTILINE_PATTERN.matcher(value).find()) {
style = '|';
}
return representScalar(tag, value, style);
}
示例5: loadAll
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
/**
* Parse all YAML documents in a String and produce corresponding Java
* objects. The documents are parsed only when the iterator is invoked.
*
* @param yaml
* YAML data to load from (BOM must not be present)
* @return an iterator over the parsed Java objects in this String in proper
* sequence
*/
public Iterable<Object> loadAll(Reader yaml) {
Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
constructor.setComposer(composer);
Iterator<Object> result = new Iterator<Object>() {
public boolean hasNext() {
return constructor.checkData();
}
public Object next() {
return constructor.getData();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new YamlIterable(result);
}
示例6: loadAll
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
/**
* Parse all YAML documents in a String and produce corresponding Java
* objects. The documents are parsed only when the iterator is invoked.
*
* @param yaml
* YAML data to load from (BOM must not be present)
* @return an iterator over the parsed Java objects in this String in proper
* sequence
*/
public Iterable<Object> loadAll(Reader yaml) {
Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
constructor.setComposer(composer);
Iterator<Object> result = new Iterator<Object>() {
public boolean hasNext() {
return constructor.checkData();
}
public Object next() {
return constructor.getData();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new YamlIterable(result);
}
示例7: composeAll
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
/**
* Parse all YAML documents in a stream and produce corresponding
* representation trees.
*
* @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
* @param yaml
* stream of YAML documents
* @return parsed root Nodes for all the specified YAML documents
*/
public Iterable<Node> composeAll(Reader yaml) {
final Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
constructor.setComposer(composer);
Iterator<Node> result = new Iterator<Node>() {
public boolean hasNext() {
return composer.checkNode();
}
public Node next() {
return composer.getNode();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new NodeIterable(result);
}
示例8: parse
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
/**
* Parse a YAML stream and produce parsing events.
*
* @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
* @param yaml
* YAML document(s)
* @return parsed events
*/
public Iterable<Event> parse(Reader yaml) {
final Parser parser = new ParserImpl(new StreamReader(yaml));
Iterator<Event> result = new Iterator<Event>() {
public boolean hasNext() {
return parser.peekEvent() != null;
}
public Event next() {
return parser.getEvent();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new EventIterable(result);
}
示例9: fromYaml
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
/**
* Parse the only YAML document in a stream as configuration object.
*
* @param template
* template of config object.
* @param io
* data to load from (BOM must not be present)
* @param <T>
* type of config object.
*
* @return parsed object
*/
@SuppressWarnings("unchecked")
@Nullable
public <T extends Config> T fromYaml(ConfigTemplate<T> template, Reader io)
{
ClassLoader old = Thread.currentThread().getContextClassLoader();
if (old == null)
{
Thread.currentThread().setContextClassLoader(template.getConfigType().getClassLoader());
}
try
{
Composer composer = new Composer(new ParserImpl(new StreamReader(io)), new ConfigTemplateResolver(template));
this.constructor.setComposer(composer);
return (T) this.constructor.getSingleData(template.getConfigType());
}
finally
{
if (old == null)
{
Thread.currentThread().setContextClassLoader(null);
}
}
}
示例10: loadFromReader
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
@Nullable
private Object loadFromReader(StreamReader sreader, Class<?> type)
{
ClassLoader old = Thread.currentThread().getContextClassLoader();
if (old == null)
{
Thread.currentThread().setContextClassLoader(type.getClassLoader());
}
try
{
Composer composer = new Composer(new ParserImpl(sreader), this.resolver);
this.constructor.setComposer(composer);
return this.constructor.getSingleData(type);
}
finally
{
if (old == null)
{
Thread.currentThread().setContextClassLoader(null);
}
}
}
示例11: testGetEvent
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
public void testGetEvent() {
String data = "string: abcd";
StreamReader reader = new StreamReader(data);
Parser parser = new ParserImpl(reader);
Mark dummyMark = new Mark("dummy", 0, 0, 0, "", 0);
LinkedList<Event> etalonEvents = new LinkedList<Event>();
etalonEvents.add(new StreamStartEvent(dummyMark, dummyMark));
etalonEvents.add(new DocumentStartEvent(dummyMark, dummyMark, false, null, null));
etalonEvents.add(new MappingStartEvent(null, null, true, dummyMark, dummyMark,
Boolean.FALSE));
etalonEvents.add(new ScalarEvent(null, null, new ImplicitTuple(true, false), "string",
dummyMark, dummyMark, (char) 0));
etalonEvents.add(new ScalarEvent(null, null, new ImplicitTuple(true, false), "abcd",
dummyMark, dummyMark, (char) 0));
etalonEvents.add(new MappingEndEvent(dummyMark, dummyMark));
etalonEvents.add(new DocumentEndEvent(dummyMark, dummyMark, false));
etalonEvents.add(new StreamEndEvent(dummyMark, dummyMark));
check(etalonEvents, parser);
}
示例12: testGetEvent2
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
public void testGetEvent2() {
String data = "american:\n - Boston Red Sox";
StreamReader reader = new StreamReader(data);
Parser parser = new ParserImpl(reader);
Mark dummyMark = new Mark("dummy", 0, 0, 0, "", 0);
LinkedList<Event> etalonEvents = new LinkedList<Event>();
etalonEvents.add(new StreamStartEvent(dummyMark, dummyMark));
etalonEvents.add(new DocumentStartEvent(dummyMark, dummyMark, false, null, null));
etalonEvents
.add(new MappingStartEvent(null, null, true, dummyMark, dummyMark, Boolean.TRUE));
etalonEvents.add(new ScalarEvent(null, null, new ImplicitTuple(true, false), "american",
dummyMark, dummyMark, (char) 0));
etalonEvents.add(new SequenceStartEvent(null, null, true, dummyMark, dummyMark,
Boolean.FALSE));
etalonEvents.add(new ScalarEvent(null, null, new ImplicitTuple(true, false),
"Boston Red Sox", dummyMark, dummyMark, (char) 0));
etalonEvents.add(new SequenceEndEvent(dummyMark, dummyMark));
etalonEvents.add(new MappingEndEvent(dummyMark, dummyMark));
etalonEvents.add(new DocumentEndEvent(dummyMark, dummyMark, false));
etalonEvents.add(new StreamEndEvent(dummyMark, dummyMark));
check(etalonEvents, parser);
}
示例13: testGetToken
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
public void testGetToken() {
String data = "string: abcd";
StreamReader reader = new StreamReader(data);
Scanner scanner = new ScannerImpl(reader);
Mark dummy = new Mark("dummy", 0, 0, 0, "", 0);
LinkedList<Token> etalonTokens = new LinkedList<Token>();
etalonTokens.add(new StreamStartToken(dummy, dummy));
etalonTokens.add(new BlockMappingStartToken(dummy, dummy));
etalonTokens.add(new KeyToken(dummy, dummy));
etalonTokens.add(new ScalarToken("string", true, dummy, dummy, (char) 0));
etalonTokens.add(new ValueToken(dummy, dummy));
etalonTokens.add(new ScalarToken("abcd", true, dummy, dummy, (char) 0));
etalonTokens.add(new BlockEndToken(dummy, dummy));
etalonTokens.add(new StreamEndToken(dummy, dummy));
while (!etalonTokens.isEmpty() && scanner.checkToken(etalonTokens.get(0).getTokenId())) {
assertEquals(etalonTokens.removeFirst(), scanner.getToken());
}
assertFalse("Must contain no more tokens: " + scanner.getToken(),
scanner.checkToken(new Token.ID[0]));
}
示例14: loadAll
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
@Override
public Iterable<Object> loadAll(Reader yaml) {
StreamReader reader = new StreamReader(yaml);
StringBuilder buffer = new StringBuilder();
while (reader.peek() != '\0') {
buffer.append(reader.peek());
reader.forward();
}
CanonicalParser parser = new CanonicalParser(buffer.toString());
Composer composer = new Composer(parser, resolver);
this.constructor.setComposer(composer);
Iterator<Object> result = new Iterator<Object>() {
public boolean hasNext() {
return constructor.checkData();
}
public Object next() {
return constructor.getData();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
return new YamlIterable(result);
}
示例15: testGetEvent
import org.yaml.snakeyaml.reader.StreamReader; //导入依赖的package包/类
public void testGetEvent() {
String data = "string: abcd";
StreamReader reader = new StreamReader(data);
Parser parser = new ParserImpl(reader);
Mark dummyMark = new Mark("dummy", 0, 0, 0, "", 0);
LinkedList<Event> etalonEvents = new LinkedList<Event>();
etalonEvents.add(new StreamStartEvent(dummyMark, dummyMark));
etalonEvents.add(new DocumentStartEvent(dummyMark, dummyMark, false, null, null));
etalonEvents.add(new MappingStartEvent(null, null, true, dummyMark, dummyMark,
Boolean.FALSE));
etalonEvents.add(new ScalarEvent(null, null, new ImplicitTuple(true, false), "string",
dummyMark, dummyMark, (char) 0));
etalonEvents.add(new ScalarEvent(null, null, new ImplicitTuple(true, false), "abcd",
dummyMark, dummyMark, (char) 0));
etalonEvents.add(new MappingEndEvent(dummyMark, dummyMark));
etalonEvents.add(new DocumentEndEvent(dummyMark, dummyMark, false));
etalonEvents.add(new StreamEndEvent(dummyMark, dummyMark));
while (parser.checkEvent(null)) {
Event event = parser.getEvent();
if (etalonEvents.isEmpty()) {
fail("unexpected event: " + event);
}
assertEquals(etalonEvents.removeFirst(), event);
}
assertFalse("Must contain no more events: " + parser.getEvent(), parser.checkEvent(null));
}