r01f.io
Class ByteArrayChunkedIterator

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

public class ByteArrayChunkedIterator
extends java.lang.Object
implements BytesChunkedIterator

Abstrae al cliente de la lógica de iterar sobre un array 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  byte[] _bytes
           
private  int _endOffset
           
private  int _initOffset
           
 
Constructor Summary
ByteArrayChunkedIterator()
           
ByteArrayChunkedIterator(byte[] bytes)
           
 
Method Summary
private  void _computeBlockSize()
           
 void close()
           
 int getOffset()
           
 boolean hasNext()
           
 byte[] next()
           
 void remove()
           
 void setBytes(byte[] bytes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_bytes

private byte[] _bytes

_initOffset

private int _initOffset

_endOffset

private int _endOffset

_block

private int _block
Constructor Detail

ByteArrayChunkedIterator

public ByteArrayChunkedIterator()

ByteArrayChunkedIterator

public ByteArrayChunkedIterator(byte[] bytes)
Method Detail

setBytes

public void setBytes(byte[] bytes)

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

_computeBlockSize

private void _computeBlockSize()

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[]>