当前位置: 首页>>代码示例>>Java>>正文


Java StringReader.read方法代码示例

本文整理汇总了Java中java.io.StringReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java StringReader.read方法的具体用法?Java StringReader.read怎么用?Java StringReader.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.StringReader的用法示例。


在下文中一共展示了StringReader.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changeLess32toXML

import java.io.StringReader; //导入方法依赖的package包/类
/**
 * Method changeLess32toXML
 *
 * @param string
 * @return normalized string
 * @throws IOException
 */
static String changeLess32toXML(String string) throws IOException {
    StringBuilder sb = new StringBuilder();
    StringReader sr = new StringReader(string);
    int i = 0;

    while ((i = sr.read()) > -1) {
        if (i < 32) {
            sb.append('\\');
            sb.append(Integer.toHexString(i));
        } else {
            sb.append((char) i);
        }
    }

    return sb.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:RFC2253Parser.java

示例2: nextNibble

import java.io.StringReader; //导入方法依赖的package包/类
private static int nextNibble(StringReader r) throws IOException {
    while (true) {
        int ch = r.read();
        if (ch == -1) {
            return -1;
        } else if ((ch >= '0') && (ch <= '9')) {
            return ch - '0';
        } else if ((ch >= 'a') && (ch <= 'f')) {
            return ch - 'a' + 10;
        } else if ((ch >= 'A') && (ch <= 'F')) {
            return ch - 'A' + 10;
        } else if (ch == 'X') {
            return -2;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TestTransmit.java

示例3: skipLws

import java.io.StringReader; //导入方法依赖的package包/类
private static int skipLws(StringReader input, boolean withReset)
        throws IOException {

    if (withReset) {
        input.mark(1);
    }
    int c = input.read();

    while (c == 32 || c == 9 || c == 10 || c == 13) {
        if (withReset) {
            input.mark(1);
        }
        c = input.read();
    }

    if (withReset) {
        input.reset();
    }
    return c;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:21,代码来源:HttpParser.java

示例4: skipConstant

import java.io.StringReader; //导入方法依赖的package包/类
private static SkipConstantResult skipConstant(StringReader input,
        String constant) throws IOException {
    int len = constant.length();

    int c = skipLws(input, false);

    for (int i = 0; i < len; i++) {
        if (i == 0 && c == -1) {
            return SkipConstantResult.EOF;
        }
        if (c != constant.charAt(i)) {
            input.skip(-(i + 1));
            return SkipConstantResult.NOT_FOUND;
        }
        if (i != (len - 1)) {
            c = input.read();
        }
    }
    return SkipConstantResult.FOUND;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:21,代码来源:HttpParser.java

示例5: readToken

import java.io.StringReader; //导入方法依赖的package包/类
/**
 * @return the token if one was found, the empty string if no data was
 *         available to read or <code>null</code> if data other than a token
 *         was found
 */
private static String readToken(StringReader input) throws IOException {
	StringBuilder result = new StringBuilder();

	int c = skipLws(input, false);

	while (c != -1 && isToken(c)) {
		result.append((char) c);
		c = input.read();
	}
	// Skip back so non-token character is available for next read
	input.skip(-1);

	if (c != -1 && result.length() == 0) {
		return null;
	} else {
		return result.toString();
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:24,代码来源:HttpParser.java

示例6: skipLws

import java.io.StringReader; //导入方法依赖的package包/类
private static int skipLws(StringReader input, boolean withReset) throws IOException {

		if (withReset) {
			input.mark(1);
		}
		int c = input.read();

		while (c == 32 || c == 9 || c == 10 || c == 13) {
			if (withReset) {
				input.mark(1);
			}
			c = input.read();
		}

		if (withReset) {
			input.reset();
		}
		return c;
	}
 
开发者ID:how2j,项目名称:lazycat,代码行数:20,代码来源:HttpParser.java

示例7: changeWStoXML

import java.io.StringReader; //导入方法依赖的package包/类
/**
 * Method changeWStoXML
 *
 * @param string
 * @return normalized string
 * @throws IOException
 */
static String changeWStoXML(String string) throws IOException {
    StringBuilder sb = new StringBuilder();
    StringReader sr = new StringReader(string);
    int i = 0;
    char c;

    while ((i = sr.read()) > -1) {
        c = (char) i;

        if (c == '\\') {
            char c1 = (char) sr.read();

            if (c1 == ' ') {
                sb.append('\\');

                String s = "20";

                sb.append(s);
            } else {
                sb.append('\\');
                sb.append(c1);
            }
        } else {
            sb.append(c);
        }
    }

    return sb.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:RFC2253Parser.java

示例8: splitFormulas

import java.io.StringReader; //导入方法依赖的package包/类
/**
 * @param A string containing a comma separated list of formulas
 * @return an array with the input formulas split up
 * @throws IOException
 */
public String[] splitFormulas(String str) throws IOException {
    StringReader strR = new StringReader(str);
    ArrayList<String> formulaList = new ArrayList<String>();

    int next;
    StringBuilder strB = new StringBuilder();
    int unmatchedLeftPar = 0;
    while ((next = strR.read()) != -1) {
        char ch = (char) next;

        switch (ch) {
            case ',':
                if (unmatchedLeftPar == 0) {
                    formulaList.add(strB + "");
                    strB = new StringBuilder();
                    continue;
                }
                break;

            case '(':
                unmatchedLeftPar++;
                break;

            case ')':
                unmatchedLeftPar = (unmatchedLeftPar == 0) ? 0 : --unmatchedLeftPar;
                break;

            default:
                break;
        }
        if(ch != ' '){
        	strB.append(ch);
        }

    }
    formulaList.add(strB + "");
    return formulaList.toArray(new String[formulaList.size()]);
}
 
开发者ID:nonilole,项目名称:Conan,代码行数:44,代码来源:HelpView.java

示例9: normalizeV

import java.io.StringReader; //导入方法依赖的package包/类
/**
 * Method normalizeV
 *
 * @param str
 * @param toXml
 * @return normalized string
 * @throws IOException
 */
static String normalizeV(String str, boolean toXml) throws IOException {
    String value = trim(str);

    if (value.startsWith("\"")) {
        StringBuilder sb = new StringBuilder();
        StringReader sr = new StringReader(value.substring(1, value.length() - 1));
        int i = 0;
        char c;

        while ((i = sr.read()) > -1) {
            c = (char) i;

            //the following char is defined at 4.Relationship with RFC1779 and LDAPv2 inrfc2253
            if ((c == ',') || (c == '=') || (c == '+') || (c == '<')
                || (c == '>') || (c == '#') || (c == ';')) {
                sb.append('\\');
            }

            sb.append(c);
        }

        value = trim(sb.toString());
    }

    if (toXml) {
        if (value.startsWith("#")) {
            value = '\\' + value;
        }
    } else {
        if (value.startsWith("\\#")) {
            value = value.substring(1);
        }
    }

    return value;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:RFC2253Parser.java

示例10: decode

import java.io.StringReader; //导入方法依赖的package包/类
public static String decode(StringReader reader, int key) throws IOException {
    int a;
    StringBuffer res = new StringBuffer();

    try {
        while ((a = reader.read()) != -1) {
            res.append(Character.toString((char) (a + key)));
        }
    } catch (Exception e) {
        return new String();
    }

    return res.toString();
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:15,代码来源:Solution.java

示例11: main

import java.io.StringReader; //导入方法依赖的package包/类
public static void main(String[] args)
throws IOException{
    StringReader in=new StringReader(
            BufferedInputFile.read("./src/main/java/io/source/hello.txt"));
    int c;
    while ((c=in.read())!=-1){
        System.out.print((char)c);
    }
}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:10,代码来源:MemoryInput.java

示例12: init

import java.io.StringReader; //导入方法依赖的package包/类
public void init() throws IOException {
  final StringReader reader = new StringReader(this.relationData);

  int open = 0;
  int offset = 1;
  int c = reader.read();
  while (c != -1) {
    if (c == '[' || c == '{') {
      open++;
    } else if (c == ']' || c == '}') {
      open--;
    }

    if (open == 1 && c == ',') {
      reader.close();
      break;
    }

    offset++;
    c = reader.read();
  }
  reader.close();

  if (offset > this.relationData.length()) {
    this.lowerBoundData =
        this.relationData.substring(this.relationData.indexOf("[") + 1, offset - 2);
    this.upperBoundData = this.relationData.substring(offset - 2, this.relationData.length() - 1);
  } else {
    this.lowerBoundData =
        this.relationData.substring(this.relationData.indexOf("[") + 1, offset - 1);
    this.upperBoundData = this.relationData.substring(offset, this.relationData.length() - 1);
  }

  this.parse2Tuples();
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:36,代码来源:RelationParser.java

示例13: readQuotedString

import java.io.StringReader; //导入方法依赖的package包/类
/**
 * @return the quoted string if one was found, null if data other than a
 *         quoted string was found or null if the end of data was reached
 *         before the quoted string was terminated
 */
private static String readQuotedString(StringReader input,
        boolean returnQuoted) throws IOException {

    int c = skipLws(input, false);

    if (c != '"') {
        return null;
    }

    StringBuilder result = new StringBuilder();
    if (returnQuoted) {
        result.append('\"');
    }
    c = input.read();

    while (c != '"') {
        if (c == -1) {
            return null;
        } else if (c == '\\') {
            c = input.read();
            if (returnQuoted) {
                result.append('\\');
            }
            result.append(c);
        } else {
            result.append((char) c);
        }
        c = input.read();
    }
    if (returnQuoted) {
        result.append('\"');
    }

    return result.toString();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:41,代码来源:HttpParser.java

示例14: readQuotedToken

import java.io.StringReader; //导入方法依赖的package包/类
/**
 * Token can be read unambiguously with or without surrounding quotes so
 * this parsing method for token permits optional surrounding double quotes.
 * This is not defined in any RFC. It is a special case to handle data from
 * buggy clients (known buggy clients for DIGEST auth include Microsoft IE 8
 * &amp; 9, Apple Safari for OSX and iOS) that add quotes to values that
 * should be tokens.
 *
 * @return the token if one was found, null if data other than a token or
 *         quoted token was found or null if the end of data was reached
 *         before a quoted token was terminated
 */
private static String readQuotedToken(StringReader input)
        throws IOException {

    StringBuilder result = new StringBuilder();
    boolean quoted = false;

    int c = skipLws(input, false);

    if (c == '"') {
        quoted = true;
    } else if (c == -1 || !isToken(c)) {
        return null;
    } else {
        result.append((char) c);
    }
    c = input.read();

    while (c != -1 && isToken(c)) {
        result.append((char) c);
        c = input.read();
    }

    if (quoted) {
        if (c != '"') {
            return null;
        }
    } else {
        // Skip back so non-token character is available for next read
        input.skip(-1);
    }

    if (c != -1 && result.length() == 0) {
        return null;
    } else {
        return result.toString();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:50,代码来源:HttpParser.java

示例15: execute

import java.io.StringReader; //导入方法依赖的package包/类
@Override
public boolean execute(String[] tokens, String line) throws Exception {
    if (tokens.length < 3) {
        err.println("Usage: " + syntaxString());
        return false;

    }
    if (!checkStoreSettings()) return false;

    StringReader sr = new StringReader(line);
    while (sr.read() != ' ');
    JsonParser jp = mjf.createJsonParser(sr);
    
    JsonNode keyNode = validateJson(jp);
    if (keyNode == null) return false;
    JsonNode valueNode = validateJson(jp);
    if (valueNode == null) return false;

    ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
    out.println("Putting Key:");
    out.println(writer.writeValueAsString(keyNode));
    out.println("\nValue:");
    out.println(writer.writeValueAsString(valueNode));
    out.flush();

    storeClient.put(keyNode, valueNode);
    out.println("Success");
                
    return false;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:31,代码来源:SyncClient.java


注:本文中的java.io.StringReader.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。