r01f.io
Class ByteStreamChunkedIterator

java.lang.Object
  extended by r01f.io.ByteStreamChunkedIterator
All Implemented Interfaces:
java.io.Closeable, java.util.Iterator<byte[]>, BytesChunkedIterator

public class ByteStreamChunkedIterator
extends java.lang.Object
implements BytesChunkedIterator

Abstrae al cliente de la lógica de iterar sobre un stream de bytes para trocearlo en paquetes Esta clase es de utilidad por ejemplo cuando un churro de bytes hay que enviarlo en paquetes (chunks) por ejemplo a otro servidor (ej: subir ficheros a iw) De esta forma, el cliente se abstrae de la complejidad de implementar el troceado del churro de entrada Ejemplo de uso:

                R01MContentDataAPI contentDataAPI = R01MClientFactory.getContentDataAPI(_userCtx,contentOid);
                ChunkedIterator bytesIt = new ByteStreamChunkedIterator(is);    // cambiar por new ByteArrayChunkedIterator(fileBytes) si en lugar de un InputStream se pasa un array de bytes 
                while (bytesIt.hasNext()) {
                        int offset = bytesIt.getOffset();
                        byte[] bytes = bytesIt.next();
                        contentDataAPI.uploadAttachmentFileChunk(documentOid,path,bytes,offset);
                }
 


Field Summary
private  int _block
           
private  java.io.InputStream _is
           
private  int _offset
           
 
Constructor Summary
ByteStreamChunkedIterator()
           
ByteStreamChunkedIterator(java.io.InputStream is)
           
 
Method Summary
 void close()
           
 int getOffset()
           
 boolean hasNext()
           
 byte[] next()
           
 void remove()
           
 void setInputStream(java.io.InputStream theIs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_is

private java.io.InputStream _is

_offset

private int _offset

_block

private int _block
Constructor Detail

ByteStreamChunkedIterator

public ByteStreamChunkedIterator()

ByteStreamChunkedIterator

public ByteStreamChunkedIterator(java.io.InputStream is)
Method Detail

setInputStream

public void setInputStream(java.io.InputStream theIs)

getOffset

public int getOffset()
Specified by:
getOffset in interface BytesChunkedIterator

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException

next

public byte[] next()
Specified by:
next in interface java.util.Iterator<byte[]>

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<byte[]>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<byte[]>