|
Last change
on this file was 36483, checked in by stoecker, 5 months ago |
|
set eol-style, fix checkstyle issues, add ignores
|
-
Property svn:eol-style
set to
native
|
|
File size:
936 bytes
|
| Line | |
|---|
| 1 | package org.j7zip.Common;
|
|---|
| 2 |
|
|---|
| 3 | public class ByteBuffer {
|
|---|
| 4 | int _capacity;
|
|---|
| 5 | byte [] _items;
|
|---|
| 6 |
|
|---|
| 7 | public ByteBuffer() {
|
|---|
| 8 | _capacity = 0;
|
|---|
| 9 | _items = null;
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | public byte [] data() { return _items; }
|
|---|
| 13 |
|
|---|
| 14 | public int GetCapacity() { return _capacity; }
|
|---|
| 15 |
|
|---|
| 16 | public void SetCapacity(int newCapacity) {
|
|---|
| 17 | if (newCapacity == _capacity)
|
|---|
| 18 | return;
|
|---|
| 19 |
|
|---|
| 20 | byte [] newBuffer;
|
|---|
| 21 | if (newCapacity > 0) {
|
|---|
| 22 | newBuffer = new byte[newCapacity];
|
|---|
| 23 | if(_capacity > 0) {
|
|---|
| 24 | int len = _capacity;
|
|---|
| 25 | if (newCapacity < len) len = newCapacity;
|
|---|
| 26 |
|
|---|
| 27 | System.arraycopy(_items,0,newBuffer,0,len); // for (int i = 0 ; i < len ; i++) newBuffer[i] = _items[i];
|
|---|
| 28 | }
|
|---|
| 29 | } else
|
|---|
| 30 | newBuffer = null;
|
|---|
| 31 |
|
|---|
| 32 | // delete []_items;
|
|---|
| 33 | _items = newBuffer;
|
|---|
| 34 | _capacity = newCapacity;
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.