Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.qiniu.android.http;
 
 import  org.apache.http.entity.AbstractHttpEntity;
 
定义请求字节实体及相关方法
public final class ByteArrayEntity extends AbstractHttpEntity implements Cloneable {
    private final byte[] b;
    private final int offlen;
    private final ProgressHandler progressHandler;
    private final CancellationHandler cancellationHandler;
    private static final int progressStep = 8 * 1024;
    public ByteArrayEntity(final byte[] bProgressHandler hCancellationHandler c) {
        this(b, 0, b.lengthhc);
    }
    public ByteArrayEntity(final byte[] bfinal int offfinal int lenProgressHandler h,  CancellationHandler c) {
        super();
        if ((off < 0) || (off > b.length) || (len < 0) ||
                ((off + len) < 0) || ((off + len) > b.length)) {
            throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length);
        }
        this. = b;
        this. = off;
        this. = len;
        this. = h;
        this. = c;
    }
    @Override
    public boolean isRepeatable() {
        return true;
    }
    @Override
    public long getContentLength() {
        return this.;
    }
    @Override
    public InputStream getContent() {
        return new ByteArrayInputStream(this.this.this.);
    }
   // @Override
    public void writeTo(final OutputStream outStreamthrows IOException {
        if( != null ||  != null){
            writeWithNotify(outStream);
        } else {
            outStream.write(this.this.this.);
        }
        outStream.flush();
    }
    private void writeWithNotify(final OutputStream outStreamthrows IOException {
        int off = 0;
        while (off < this.) {
            if( != null && .isCancelled()) {
                try {
                    outStream.close();
                } catch (Exception e) {
                    // ignore
                }
                throw new CancellationHandler.CancellationException();
            }
            int left = this. - off;
            int len = left <  ? left : ;
            outStream.write(this.this. + offlen);
            if( != null) {
                .onProgress(offthis.);
            }
            off += len;
        }
    }

    
Tells that this entity is not streaming.

Returns:
false
    @Override
    public boolean isStreaming() {
        return false;
    }
    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
New to GrepCode? Check out our FAQ X