首页

关于imageio的imageio-ext-utilities源码包FastByteArrayWrapper二进制序列包装类源码说明

标签:imageio,imageio-ext-utilities,FastByteArrayWrapper,二进制序列包装类     发布时间:2018-07-03   

一、前言

关于imageio的imageio-ext-utilities-1.0.6-1.jar源码包中it.geosolutions.imageio.utilities.FastByteArrayWrapper二进制序列包装类,基于二进制数组byte[]实现Array自定义序列,具体参见源码说明。

二、源码说明

package it.geosolutions.imageio.utilities;@b@@b@import java.io.IOException;@b@@b@public class FastByteArrayWrapper@b@{@b@  protected byte[] buf;@b@  protected int count;@b@@b@  public FastByteArrayWrapper()@b@  {@b@    this(32);@b@  }@b@@b@  public FastByteArrayWrapper(byte[] buffer)@b@  {@b@    this(buffer, 0);@b@  }@b@@b@  public FastByteArrayWrapper(byte[] buffer, int count)@b@  {@b@    if ((count < 0) || ((buffer != null) && (count > buffer.length)))@b@      throw new IllegalArgumentException("The specified count is invalid. It can't be lower than zero or greater than the length of the provided buffer");@b@@b@    this.buf = buffer;@b@    this.count = count;@b@  }@b@@b@  public FastByteArrayWrapper(int size)@b@  {@b@    if (size < 0)@b@      throw new IllegalArgumentException("Negative initial size: " + size);@b@    this.buf = new byte[size];@b@  }@b@@b@  public void write(int b)@b@  {@b@    int newcount = this.count + 1;@b@    if (newcount > this.buf.length) {@b@      byte[] newbuf = new byte[Math.max(this.buf.length << 1, newcount)];@b@      System.arraycopy(this.buf, 0, newbuf, 0, this.count);@b@      this.buf = newbuf;@b@    }@b@    this.buf[this.count] = (byte)b;@b@    this.count = newcount;@b@  }@b@@b@  public void write(byte[] b, int off, int len)@b@  {@b@    if ((off < 0) || (off > b.length) || (len < 0) || (off + len > b.length) || (off + len < 0))@b@    {@b@      throw new IndexOutOfBoundsException(); }@b@    if (len == 0)@b@      return;@b@@b@    int newcount = this.count + len;@b@    if (newcount > this.buf.length) {@b@      byte[] newbuf = new byte[Math.max(this.buf.length << 1, newcount)];@b@      System.arraycopy(this.buf, 0, newbuf, 0, this.count);@b@      this.buf = newbuf;@b@    }@b@    System.arraycopy(b, off, this.buf, this.count, len);@b@    this.count = newcount;@b@  }@b@@b@  public void write(byte[] b)@b@    throws IOException@b@  {@b@    write(b, 0, b.length);@b@  }@b@@b@  public void reset()@b@  {@b@    this.count = 0;@b@  }@b@@b@  public byte[] getByteArray()@b@  {@b@    return this.buf;@b@  }@b@@b@  public int size()@b@  {@b@    return this.count;@b@  }@b@@b@  public String toString()@b@  {@b@    return new String(this.buf, 0, this.count);@b@  }@b@}