public static Object read( String value ) throws IOException { PushbackReader pr = new PushbackReader( new StringReader( value ), 1 ); ConfigurationHandler ch = new ConfigurationHandler(); return ch.readValue(pr); }
for ( ;; ) int c = ignorablePageBreakAndWhiteSpace( pr ); if ( c == TOKEN_VAL_OPEN ) Object value = readSimple( typeCode, pr ); if ( value == null ) ensureNext( pr, TOKEN_VAL_CLOS ); c = ignorablePageBreakAndWhiteSpace( pr );
private int read( PushbackReader pr, char[] buf ) throws IOException { for ( int i = 0; i < buf.length; i++ ) { int c = read( pr ); if ( c >= 0 ) { buf[i] = ( char ) c; } else { return i; } } return buf.length; }
private void ensureNext( PushbackReader pr, int expected ) throws IOException { int next = read( pr ); if ( next != expected ) { readFailure( next, expected ); } }
/** * Reads configuration data from the given <code>InputStream</code> and * returns a new <code>Dictionary</code> object containing the data. * <p> * This method reads from the current location in the stream upto the end of * the stream but does not close the stream at the end. * * @param ins * The <code>InputStream</code> from which to read the * configuration data. * @return A <code>Dictionary</code> object containing the configuration * data. This object may be empty if the stream contains no * configuration data. * @throws IOException * If an error occurrs reading from the stream. This exception * is also thrown if a syntax error is encountered. */ public static Dictionary read( InputStream ins ) throws IOException { return new ConfigurationHandler().readInternal( ins ); }
int type = ignorableWhiteSpace( pr ); if ( code2Type.containsKey( new Integer( type ) ) ) code = read( pr ); return readArray( type, pr ); return readCollection( type, pr ); Object value = readSimple( type, pr ); ensureNext( pr, TOKEN_VAL_CLOS ); return value;
private int nextToken( PushbackReader pr, final boolean newLine ) throws IOException int c = ignorableWhiteSpace( pr ); c = read( pr ); } while ( c != -1 && c != '\n' ); if ( c == -1 ) return nextToken( pr, true ); tokenValue = readUnquoted( pr ); return ( token = TOKEN_NAME );
private Dictionary readInternal( InputStream ins ) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader( ins, ENCODING ) ); PushbackReader pr = new PushbackReader( br, 1 ); token = 0; tokenValue = null; line = 0; pos = 0; Hashtable configuration = new Hashtable(); token = 0; while ( nextToken( pr, true ) == TOKEN_NAME ) { String key = tokenValue; // expect equal sign if ( nextToken( pr, false ) != TOKEN_EQ ) { throw readFailure( token, TOKEN_EQ ); } // expect the token value Object value = readValue( pr ); if ( value != null ) { configuration.put( key, value ); } } return configuration; }
/** * Writes the configuration data from the <code>Dictionary</code> to the * given <code>OutputStream</code>. * <p> * This method writes at the current location in the stream and does not * close the outputstream. * * @param out * The <code>OutputStream</code> to write the configurtion data * to. * @param properties * The <code>Dictionary</code> to write. * @throws IOException * If an error occurrs writing to the output stream. */ public static void write( OutputStream out, Dictionary properties ) throws IOException { BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( out, ENCODING ) ); for ( Enumeration ce = orderedKeys(properties); ce.hasMoreElements(); ) { String key = ( String ) ce.nextElement(); // cfg = prop "=" value "." . writeQuoted( bw, key ); bw.write( TOKEN_EQ ); writeValue( bw, properties.get( key ) ); bw.write( CRLF ); } bw.flush(); }
private int ignorablePageBreakAndWhiteSpace( PushbackReader pr ) throws IOException { int c = ignorableWhiteSpace( pr ); for ( ;; ) { if ( c != '\\' ) { break; } int c1 = pr.read(); if ( c1 == '\r' || c1 == '\n' ) { c = ignorableWhiteSpace( pr ); } else { pr.unread(c1); break; } } return c; }
int type = ignorableWhiteSpace( pr ); if ( code2Type.containsKey( new Integer( type ) ) ) code = read( pr ); return readArray( type, pr ); return readCollection( type, pr ); Object value = readSimple( type, pr ); ensureNext( pr, TOKEN_VAL_CLOS ); return value;
private int nextToken( PushbackReader pr, final boolean newLine ) throws IOException int c = ignorableWhiteSpace( pr ); c = read( pr ); } while ( c != -1 && c != '\n' ); if ( c == -1 ) return nextToken( pr, true ); tokenValue = readUnquoted( pr ); return ( token = TOKEN_NAME );
private Dictionary readInternal( InputStream ins ) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader( ins, ENCODING ) ); PushbackReader pr = new PushbackReader( br, 1 ); token = 0; tokenValue = null; line = 0; pos = 0; Hashtable configuration = new Hashtable(); token = 0; while ( nextToken( pr, true ) == TOKEN_NAME ) { String key = tokenValue; // expect equal sign if ( nextToken( pr, false ) != TOKEN_EQ ) { throw readFailure( token, TOKEN_EQ ); } // expect the token value Object value = readValue( pr ); if ( value != null ) { configuration.put( key, value ); } } return configuration; }
/** * Writes the configuration data from the <code>Dictionary</code> to the * given <code>OutputStream</code>. * <p> * This method writes at the current location in the stream and does not * close the outputstream. * * @param out * The <code>OutputStream</code> to write the configurtion data * to. * @param properties * The <code>Dictionary</code> to write. * @throws IOException * If an error occurrs writing to the output stream. */ public static void write( OutputStream out, Dictionary properties ) throws IOException { BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( out, ENCODING ) ); for ( Enumeration ce = orderedKeys(properties); ce.hasMoreElements(); ) { String key = ( String ) ce.nextElement(); // cfg = prop "=" value "." . writeQuoted( bw, key ); bw.write( TOKEN_EQ ); writeValue( bw, properties.get( key ) ); bw.write( CRLF ); } bw.flush(); }
private void ensureNext( PushbackReader pr, int expected ) throws IOException { int next = read( pr ); if ( next != expected ) { readFailure( next, expected ); } }
/** * Reads configuration data from the given <code>InputStream</code> and * returns a new <code>Dictionary</code> object containing the data. * <p> * This method reads from the current location in the stream upto the end of * the stream but does not close the stream at the end. * * @param ins * The <code>InputStream</code> from which to read the * configuration data. * @return A <code>Dictionary</code> object containing the configuration * data. This object may be empty if the stream contains no * configuration data. * @throws IOException * If an error occurrs reading from the stream. This exception * is also thrown if a syntax error is encountered. */ public static Dictionary read( InputStream ins ) throws IOException { return new ConfigurationHandler().readInternal( ins ); }
private int ignorablePageBreakAndWhiteSpace( PushbackReader pr ) throws IOException { int c = ignorableWhiteSpace( pr ); for ( ;; ) { if ( c != '\\' ) { break; } int c1 = pr.read(); if ( c1 == '\r' || c1 == '\n' ) { c = ignorableWhiteSpace( pr ); } else { pr.unread(c1); break; } } return c; }
int type = ignorableWhiteSpace( pr ); if ( code2Type.containsKey( new Integer( type ) ) ) code = read( pr ); return readArray( type, pr ); return readCollection( type, pr ); Object value = readSimple( type, pr ); ensureNext( pr, TOKEN_VAL_CLOS ); return value;
for ( ;; ) int c = ignorablePageBreakAndWhiteSpace( pr ); if ( c == TOKEN_VAL_OPEN ) Object value = readSimple( typeCode, pr ); if ( value == null ) ensureNext( pr, TOKEN_VAL_CLOS ); c = ignorablePageBreakAndWhiteSpace( pr );
private int nextToken( PushbackReader pr, final boolean newLine ) throws IOException int c = ignorableWhiteSpace( pr ); c = read( pr ); } while ( c != -1 && c != '\n' ); if ( c == -1 ) return nextToken( pr, true ); tokenValue = readUnquoted( pr ); return ( token = TOKEN_NAME );