2 * Copyright 2008 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 namespace com.google.zxing.common
\r
20 /// <summary> This class implements an array of unsigned bytes.
\r
23 /// <author> dswitkin@google.com (Daniel Switkin)
\r
25 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
27 public sealed class ByteArray
\r
33 return size_Renamed_Field == 0;
\r
38 private const int INITIAL_SIZE = 32;
\r
40 private sbyte[] bytes;
\r
41 private int size_Renamed_Field;
\r
46 size_Renamed_Field = 0;
\r
49 public ByteArray(int size)
\r
51 bytes = new sbyte[size];
\r
52 this.size_Renamed_Field = size;
\r
55 public ByteArray(sbyte[] byteArray)
\r
58 size_Renamed_Field = bytes.Length;
\r
61 /// <summary> Access an unsigned byte at location index.</summary>
\r
62 /// <param name="index">The index in the array to access.
\r
64 /// <returns> The unsigned value of the byte as an int.
\r
66 public int at(int index)
\r
68 return bytes[index] & 0xff;
\r
71 public void set_Renamed(int index, int value_Renamed)
\r
73 bytes[index] = (sbyte) value_Renamed;
\r
78 return size_Renamed_Field;
\r
81 public void appendByte(int value_Renamed)
\r
83 if (size_Renamed_Field == 0 || size_Renamed_Field >= bytes.Length)
\r
85 int newSize = System.Math.Max(INITIAL_SIZE, size_Renamed_Field << 1);
\r
88 bytes[size_Renamed_Field] = (sbyte) value_Renamed;
\r
89 size_Renamed_Field++;
\r
92 public void reserve(int capacity)
\r
94 if (bytes == null || bytes.Length < capacity)
\r
96 sbyte[] newArray = new sbyte[capacity];
\r
99 Array.Copy(bytes, 0, newArray, 0, bytes.Length);
\r
105 // Copy count bytes from array source starting at offset.
\r
106 public void set_Renamed(sbyte[] source, int offset, int count)
\r
108 bytes = new sbyte[count];
\r
109 size_Renamed_Field = count;
\r
110 for (int x = 0; x < count; x++)
\r
112 bytes[x] = source[offset + x];
\r