private synchronized int flipBuffers()
	{
		if(!closed) {
			synchronized (buffer) {
				// wait until 
				while(buffer.size() <= 0) {
					try {
						buffer.wait();
					}
					catch (InterruptedException exc) {
						// ignore it
					}
					
					if(!closed) return -1;
				}
				
				// reset read buffer with buffer from output stream
				this.count = buffer.size();
				this.buf = buffer.replaceBuffer();
				this.pos = 0;
				this.mark = 0;
			}
			return this.count;
		} else {
			return -1;
		}
	}