@Override
	public int read() throws IOException {
		synchronized (this) {
			if(streamClosed){
				throw new IOException();
			}			
		}
		//test if the available input has reached its end
		//and the EOS should be returned 
		if((str != null && pos == str.length())){
			str =null;
			return java.io.StreamTokenizer.TT_EOF;
		}
		//no input available, block until more is available because that's
		//the behavior specified in the Javadocs
		while (str == null || pos >= str.length()) {
			try {
				//according to the docs read() should block until new input is available
				synchronized (this) {
					if(str == null || pos >= str.length()){
						this.wait();
					}
				}
			} catch (InterruptedException ex) {
				throw new RuntimeException(ex);
			}
		}
		//read an additional character, return it and increment the index
		return str.charAt(pos++);
	}