Java Code Examples for java.io.Reader#toString()

The following examples show how to use java.io.Reader#toString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
   Configure log4j by reading in a log4j.dtd compliant XML
   configuration file.

*/
public
void doConfigure(final Reader reader, LoggerRepository repository) 
                                        throws FactoryConfigurationError {
    ParseAction action = new ParseAction() {
        public Document parse(final DocumentBuilder parser) throws SAXException, IOException {
            InputSource inputSource = new InputSource(reader);
            inputSource.setSystemId("dummy://log4j.dtd");
            return parser.parse(inputSource);
        }
        public String toString() { 
            return "reader [" + reader.toString() + "]"; 
        }
    };
  doConfigure(action, repository);
}
 
Example 2
Source Project: netbeans   File: ScriptingTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
    throw new ScriptException(reader.toString());
}
 
Example 3
Source Project: netbeans   File: ScriptingTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object eval(Reader reader) throws ScriptException {
    throw new ScriptException(reader.toString());
}
 
Example 4
Source Project: netbeans   File: ScriptingTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object eval(Reader reader, Bindings n) throws ScriptException {
    throw new ScriptException(reader.toString());
}
 
Example 5
Source Project: reflectutils   File: TranscoderUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This will ensure that no objects that are known to be impossible to serialize properly will
 * cause problems with the transcoders by allowing them to go into loops
 * 
 * @param object
 * @return a null if the current object is not special, an empty string to indicate the 
 * object should be skipped over with no output, and any string value to indicate the
 * return value to use instead of attempting to encode the object
 */
public static String checkObjectSpecial(Object object) {
    String special = null;
    if (object != null) {
        Class<?> type = object.getClass();
        if (Class.class.isAssignableFrom(type)) {
            // class objects are serialized as the full name
            special = ((Class<?>)object).getName();
        } else if (Type.class.isAssignableFrom(type)) {
            // type just does to string
            special = ((Type)object).toString();
        } else if (Package.class.isAssignableFrom(type)) {
            // package uses name only
            special = ((Package)object).getName();
        } else if (ClassLoader.class.isAssignableFrom(type)) {
            // classloaders are skipped over entirely
            special = "";
        } else if (InputStream.class.isAssignableFrom(type)) {
            // skip IS
            special = "";
        } else if (OutputStream.class.isAssignableFrom(type)) {
            // skip OS
            special = "";
        } else if (InputStream.class.isAssignableFrom(type)) {
            // skip IS
            special = "";
        } else if (Writer.class.isAssignableFrom(type)) {
            // skip writer
            special = "";
        } else if (Reader.class.isAssignableFrom(type)) {
            // turn reader into string
            Reader reader = ((Reader)object);
            StringBuilder sb = new StringBuilder();
            try {
                while (reader.ready()) {
                    int c = reader.read();
                    if (c <= -1) {
                        break;
                    }
                    sb.append((char) c);
                }
                special = sb.toString();
            } catch (IOException e) {
                special = "Could not read from Reader ("+reader.toString()+"): " + e.getMessage();
            }
        }
    }
    return special;
}