本文整理汇总了Java中java.io.PushbackReader.unread方法的典型用法代码示例。如果您正苦于以下问题:Java PushbackReader.unread方法的具体用法?Java PushbackReader.unread怎么用?Java PushbackReader.unread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.PushbackReader
的用法示例。
在下文中一共展示了PushbackReader.unread方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseEntityReference
import java.io.PushbackReader; //导入方法依赖的package包/类
/** Parser that reads the name of entity reference and replace it with
* the content of that entity (using the pushback capability of input).
* It gets the control just after starting '%'
* @returns the name of reference which was replaced. */
private String parseEntityReference( PushbackReader in ) throws IOException, WrongDTDException {
StringBuffer sb = new StringBuffer();
for( ;; ) {
int i = in.read();
if( i == -1 ) break; // EOF
if( isNameChar( (char)i ) ) {
sb.append( (char)i ); // next char of name
} else {
String entValue = (String)entityMap.get( sb.toString() ); //get the entity content
if( entValue == null )
throw new WrongDTDException( "No such entity: \"" + sb + "\"" ); // NOI18N
if( i != ';' ) in.unread( i );
in.unread( entValue.toCharArray() ); // push it back to stream
return sb.toString();
}
}
throw new WrongDTDException( "Premature end of DTD" ); // NOI18N
}
示例2: readToken
import java.io.PushbackReader; //导入方法依赖的package包/类
private static Object readToken(PushbackReader r, IEOFHandler ieofHandler, int ch) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append((char)ch);
while(true) {
ch = r.read();
if (ch == -1) {
ieofHandler.eof();
break;
} else if (Character.isWhitespace(ch)) {
break;
} else if (ch == ')') {
r.unread(ch);
break;
} else {
sb.append((char)ch);
}
}
return interpretToken(sb.toString());
}
示例3: readMatch
import java.io.PushbackReader; //导入方法依赖的package包/类
/**
* Extracts matching character from stream.
* A non-matching character is pushed back to the stream.
*
* @param in The input.
* @param c The character to expect from the stream.
*
* @return <code>true</code> if the specified character was extracted from the stream, <code>false</code> otherwise.
*
* @exception java.io.IOException In case of read error in the stream.
*/
public static boolean readMatch(PushbackReader in, int c)
throws IOException
{
int i = in.read();
if (i != c)
{
if (i != -1)
{
in.unread(i);
}
return false;
}
return true;
}
示例4: extractWhitespace
import java.io.PushbackReader; //导入方法依赖的package包/类
/**
* Extracts whitespace from stream.
*
* @param in The input.
*
* @exception java.io.IOException In case of read error in the stream.
*/
public static void extractWhitespace(PushbackReader in)
throws IOException
{
int c;
while (Character.isWhitespace((char) (c = in.read())))
{
// Extracts any whitespace
}
if (c != -1)
{
in.unread(c);
}
}
示例5: readExponent
import java.io.PushbackReader; //导入方法依赖的package包/类
private static long readExponent(PushbackReader in)
throws IOException, NumberFormatException
{
StringBuilder buffer = new StringBuilder(20);
int input;
for (long i = 0; (input = in.read()) != -1; i++)
{
char c = (char) input;
int digit = Character.digit(c, 10); // Exponent is always in base 10
if (i == 0 && c == '-' ||
digit != -1)
{
buffer.append(c);
}
else
{
// Stop at first invalid character and put it back
in.unread(input);
break;
}
}
return Long.parseLong(buffer.toString());
}
示例6: readLine
import java.io.PushbackReader; //导入方法依赖的package包/类
/** Reads a line and returns the char sequence for newline */
private static String readLine(PushbackReader r, StringBuffer nl) throws IOException {
StringBuffer line = new StringBuffer();
int ic = r.read();
if (ic == -1) return null;
char c = (char) ic;
while (c != '\n' && c != '\r') {
line.append(c);
ic = r.read();
if (ic == -1) break;
c = (char) ic;
}
if (nl != null) {
nl.append(c);
}
if (c == '\r') {
try {
ic = r.read();
if (ic != -1) {
c = (char) ic;
if (c != '\n') r.unread(c);
else if (nl != null) nl.append(c);
}
} catch (IOException ioex) {}
}
return line.toString();
}
示例7: compareText
import java.io.PushbackReader; //导入方法依赖的package包/类
private boolean compareText(PushbackReader source, String text) throws IOException {
if (text == null || text.length() == 0) return true;
text = adjustTextNL(text);
char[] chars = new char[text.length()];
int pos = 0;
int n;
String readStr = "";
do {
n = source.read(chars, 0, chars.length - pos);
if (n > 0) {
pos += n;
readStr = readStr + new String(chars, 0, n);
}
if (readStr.endsWith("\r")) {
try {
char c = (char) source.read();
if (c != '\n') source.unread(c);
else readStr += c;
} catch (IOException ioex) {}
}
readStr = adjustTextNL(readStr);
pos = readStr.length();
} while (n > 0 && pos < chars.length);
readStr.getChars(0, readStr.length(), chars, 0);
line += numChars('\n', chars);
//System.out.println("Comparing text of the diff:\n'"+text+"'\nWith the read text:\n'"+readStr+"'\n");
//System.out.println(" EQUALS = "+readStr.equals(text));
return readStr.equals(text);
}
示例8: readList
import java.io.PushbackReader; //导入方法依赖的package包/类
private static List readList(PushbackReader r) throws IOException {
ArrayList list = new ArrayList();
while(true) {
int ch = r.read();
if (ch == -1) throw new EOFException();
if (ch == ')') break;
r.unread(ch);
list.add(read(r, ThrowOnEof));
}
return list;
}
示例9: readToken
import java.io.PushbackReader; //导入方法依赖的package包/类
private static Token readToken(char chFirst, EnumTokenType type, PushbackReader pr) throws IOException
{
StringBuffer stringbuffer = new StringBuffer();
stringbuffer.append(chFirst);
while (type.getMaxLen() <= 0 || stringbuffer.length() < type.getMaxLen())
{
int i = pr.read();
if (i < 0)
{
break;
}
char c0 = (char)i;
if (!type.hasChar(c0))
{
pr.unread(c0);
break;
}
stringbuffer.append(c0);
}
return new Token(type, stringbuffer.toString());
}
示例10: unread
import java.io.PushbackReader; //导入方法依赖的package包/类
static void unread(PushbackReader r, int ch) {
if(ch != -1)
try
{
r.unread(ch);
}
catch(IOException e)
{
throw Util.sneakyThrow(e);
}
}
示例11: parseDTD
import java.io.PushbackReader; //导入方法依赖的package包/类
private void parseDTD( PushbackReader in ) throws IOException, WrongDTDException {
int state = DTD_INIT;
for( ;; ) {
int i = in.read();
if( i == -1 ) {
break;
}
switch( state ) {
case DTD_INIT:
switch( i ) {
case '<':
state = DTD_LT;
break;
case '%':
parseEntityReference( in );
break; // Stay in DTD_INIT
}
break;
case DTD_LT:
if( i != '!' ) throw new WrongDTDException( "Unexpected char '" + (char)i + "' after '<'" ); // NOI18N
state = DTD_EXC;
break;
case DTD_EXC:
switch( i ) {
case '-':
state = DTD_MINUS;
break;
case '[':
parseOptional( in );
state = DTD_INIT;
break;
default:
in.unread( i );
parseMarkup( in );
state = DTD_INIT;
break;
}
break;
case DTD_MINUS:
if( i != '-' ) throw new WrongDTDException( "Unexpected char '" + (char)i + "' after \"<!-\"" ); // NOI18N
parseComment( in );
state = DTD_ACOMMENT;
break;
case DTD_ACOMMENT:
if( i != '>' ) throw new WrongDTDException( "Unexpected char '" + (char)i + "' after comment" ); // NOI18N
state = DTD_INIT;
break;
}
}
if( state != DTD_INIT ) throw new WrongDTDException( "Premature end of DTD" ); // NOI18N
}
示例12: parseOptional
import java.io.PushbackReader; //导入方法依赖的package包/类
/** Parser that takes care of conditional inclusion/exclusion of part
* of DTD. Gets the control just after "<![" */
private void parseOptional( PushbackReader in ) throws IOException, WrongDTDException {
int state = OPT_INIT;
StringBuffer process = new StringBuffer();
StringBuffer content = new StringBuffer();
boolean ignore = false;
for( ;; ) {
int i = in.read();
if( i == -1 ) break; // EOF
switch( state ) {
case OPT_INIT:
if( Character.isWhitespace( (char)i ) ) break;
if( i == '%' ) {
parseEntityReference( in );
break;
}
process.append( (char)i );
state = OPT_PROCESS;
break;
case OPT_PROCESS:
if( Character.isWhitespace( (char)i ) ) {
String s = process.toString();
if( "IGNORE".equals( s ) ) ignore = true; // NOI18N
else if( ! "INCLUDE".equals( s ) ) throw new WrongDTDException( "Unexpected processing instruction " + s ); // NOI18N
state = OPT_APROCESS;
} else {
process.append( (char)i );
}
break;
case OPT_APROCESS:
if( Character.isWhitespace( (char)i ) ) break;
if( i == '[' ) state = OPT_CONTENT;
else throw new WrongDTDException( "Unexpected char '" + (char)i + "' in processing instruction." ); // NOI18N
break;
case OPT_CONTENT:
if( i == ']' ) state = OPT_BRAC1;
else content.append( (char)i );
break;
case OPT_BRAC1:
if( i == ']' ) state = OPT_BRAC2;
else {
content.append( ']' ).append( (char)i );
state = OPT_CONTENT;
}
break;
case OPT_BRAC2:
if( Character.isWhitespace( (char)i ) ) break;
if( i == '>' ) {
if( !ignore ) in.unread( content.toString().toCharArray() );
return;
}
throw new WrongDTDException( "Unexpected char '" + (char)i + "' in processing instruction." ); // NOI18N
}
}
}
示例13: getProcessedSchema
import java.io.PushbackReader; //导入方法依赖的package包/类
/**
* Function gets schema template as input and translates it into series of java statements
* @param inputSchema
* @return
* @throws IOException
*/
public String getProcessedSchema(String inputSchema) throws PepperBoxException {
try {
PushbackReader pushbackReader = new PushbackReader(new StringReader(inputSchema), 80);
int chr;
StringBuilder token = new StringBuilder();
StringBuilder processedSchema = new StringBuilder();
processedSchema.append(PropsKeys.STR_BUILD_OBJ);
while ((chr = pushbackReader.read()) != -1) {
if (chr != PropsKeys.OPENING_BRACE) {
token.append((char) chr);
} else if ((chr = pushbackReader.read()) != PropsKeys.OPENING_BRACE) {
pushbackReader.unread(chr);
token.append(PropsKeys.OPENING_BRACE);
} else {
appendStaticString(token, processedSchema);
token.delete(0, token.length());
chr = pushbackReader.read();
while (chr != -1) {
if (chr != PropsKeys.CLOSING_BRACE) {
token.append((char) chr);
chr = pushbackReader.read();
} else if ((chr = pushbackReader.read()) != PropsKeys.CLOSING_BRACE) {
pushbackReader.unread((char) chr);
token.append(PropsKeys.CLOSING_BRACE);
} else {
processedSchema.append(PropsKeys.STR_APPEND);
processedSchema.append(token.toString().replaceAll(PropsKeys.ESC_QUOTE, PropsKeys.DOUBLE_ESC_QUOTE));
processedSchema.append(PropsKeys.CLOSING_BRACKET);
token.delete(0, token.length());
break;
}
}
}
}
appendStaticString(token, processedSchema);
processedSchema.append(PropsKeys.STR_TOSTRING);
return processedSchema.toString().replaceAll(PropsKeys.STR_TAB, PropsKeys.ESCAPE_TAB).replaceAll(PropsKeys.STR_NEWLINE, PropsKeys.ESCAPE_NEWLINE).replaceAll(PropsKeys.STR_CARRIAGE_RETURN, PropsKeys.ESCAPE_CARRIAGE_RETURN);
}catch (IOException e){
throw new PepperBoxException(e);
}
}