Package org.ajax4jsf.io

Examples of org.ajax4jsf.io.FastBufferOutputStream


public class FastBufferOutputStreamTest extends TestCase {
    /**
     * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
     */
    public void testResetOneBuffer() throws Exception {
        FastBufferOutputStream stream = new FastBufferOutputStream(256);

        for (int i = 0; i < 255; i++) {
            stream.write(i);
        }

        assertEquals(255, stream.getLength());

        ByteBuffer firstBuffer = stream.getFirstBuffer();

        assertNull(firstBuffer.getNext());
        assertNull(firstBuffer.getPrevious());
        stream.reset();
        assertEquals(0, stream.getLength());
        firstBuffer = stream.getFirstBuffer();
        assertEquals(0, firstBuffer.getUsedSize());
        assertNull(firstBuffer.getNext());
        assertNull(firstBuffer.getPrevious());
    }
View Full Code Here


    /**
     * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
     */
    public void testResetTwoBuffers() throws Exception {
        FastBufferOutputStream stream = new FastBufferOutputStream(256);

        for (int i = 0; i < 257; i++) {
            stream.write(i);
        }

        assertEquals(257, stream.getLength());

        ByteBuffer firstBuffer = stream.getFirstBuffer();

        assertNotNull(firstBuffer.getNext());
        assertNull(firstBuffer.getPrevious());
        stream.reset();
        assertEquals(0, stream.getLength());
        firstBuffer = stream.getFirstBuffer();
        assertEquals(0, firstBuffer.getUsedSize());
        assertNull(firstBuffer.getNext());
        assertNull(firstBuffer.getPrevious());
    }
View Full Code Here

        }

        @Override
        public FastBufferOutputStream getResponseOutputStream() {
            if (stream == null) {
                stream = new FastBufferOutputStream();
            }

            return stream;
        }
View Full Code Here

    public Java2DUserResourceWrapperImpl(Java2DUserResource resourceObject, boolean cacheable, boolean versioned) {
        super(resourceObject, cacheable, versioned);
    }

    public InputStream getInputStream() throws IOException {
        FastBufferOutputStream fbos = new FastBufferOutputStream();

        ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(fbos);
        try {
            paintAndWrite(imageOutputStream);
        } finally {
            if (imageOutputStream != null) {
                try {
                    imageOutputStream.close();
                } catch (IOException e) {
                    LOGGER.debug(e.getMessage(), e);
                }

                try {
                    fbos.close();
                } catch (IOException e) {
                    // Swallow
                }
            }
        }
        ByteBuffer buffer = fbos.getFirstBuffer();
        buffer.compact();

        return new FastBufferInputStream(buffer);
    }
View Full Code Here

    private static ByteBuffer readContent(InputStream is) throws IOException {
        if (is == null) {
            throw new NullPointerException("Resource input stream is null");
        }

        FastBufferOutputStream os = new FastBufferOutputStream();

        try {
            ResourceUtils.copyStreamContent(is, os);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(e.getMessage(), e);
                }
            }

            try {
                os.close();
            } catch (IOException e) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(e.getMessage(), e);
                }
            }
        }

        ByteBuffer buffer = os.getFirstBuffer();

        buffer.compact();

        return buffer;
    }
View Full Code Here

   * @param responseStream
   * @return
   */
  public OutputStream getOutputStream() {
    if (null == servletStream) {
      outputStream = new FastBufferOutputStream(1024);
      servletStream = new ServletOutputStream() {

        /*
         * (non-Javadoc)
         *
 
View Full Code Here

      printWriter.flush();
      printWriter.close();
      length = stringWriter.getLength();
///      String stringContent = stringWriter.toString();
      try {
        FastBufferOutputStream stream = stringWriter.convertToOutputStream(encoding);
        result = new FastBufferInputStream(stream);
///        content = stringContent.getBytes(encoding);
      } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        log.warn(Messages.getMessage(Messages.UNSUPPORTED_ENCODING_WARNING));
        FastBufferOutputStream stream = stringWriter.convertToOutputStream();
        result = new FastBufferInputStream(stream);
///        content = stringContent.getBytes();
      }
    } else  {
            if (log.isDebugEnabled()) {
View Full Code Here

      }
    }


    public ByteArrayServletOutputStream() {
            byteStream = new FastBufferOutputStream(bufferSize);
        }
View Full Code Here

  public ServletOutputStream getOutputStream() throws IOException {
    if(useWriter){
      throw new IllegalStateException();
    }
    if (!useStream) {
      _bytes = new FastBufferOutputStream(getBufferSize());
      _servletStream = new ServletOutputStream(){

        /* (non-Javadoc)
         * @see java.io.OutputStream#flush()
         */
 
View Full Code Here

 
  public void flushBuffer() throws IOException {
    if (useStream) {
      // TODO - detect encoding ?
      _bytes.writeTo(_jspWriter, getCharacterEncoding());
      _bytes = new FastBufferOutputStream(getBufferSize());
    }
  }
View Full Code Here

TOP

Related Classes of org.ajax4jsf.io.FastBufferOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.