34
34
35
35
import org .scijava .io .ByteArrayByteBank ;
36
36
import org .scijava .io .ByteBank ;
37
- import org .scijava .io .handle .DataHandle ;
38
37
import org .scijava .util .ByteArray ;
39
38
40
39
/**
@@ -47,14 +46,27 @@ public class BytesLocation extends AbstractLocation {
47
46
48
47
private final ByteBank bytes ;
49
48
49
+ private final String name ;
50
+
50
51
/**
51
52
* Creates a {@link BytesLocation} backed by the specified
52
53
* {@link ByteBank}.
53
54
*
54
55
* @param bytes the {@link ByteBank} that will back this {@link Location}
55
56
*/
56
57
public BytesLocation (final ByteBank bytes ) {
58
+ this (bytes , null );
59
+ }
60
+
61
+ /**
62
+ * Creates a {@link BytesLocation} backed by the specified {@link ByteBank}.
63
+ *
64
+ * @param bytes the {@link ByteBank} that will back this {@link Location}
65
+ * @param name the name of this {@link Location}
66
+ */
67
+ public BytesLocation (final ByteBank bytes , final String name ) {
57
68
this .bytes = bytes ;
69
+ this .name = name ;
58
70
}
59
71
60
72
/**
@@ -63,15 +75,38 @@ public BytesLocation(final ByteBank bytes) {
63
75
* can be used to avoid needing to grow the underlying {@link ByteBank}.
64
76
*/
65
77
public BytesLocation (final int initialCapacity ) {
78
+ this (initialCapacity , null );
79
+ }
80
+
81
+ /**
82
+ * Creates a {@link BytesLocation} backed by a {@link ByteArrayByteBank} with
83
+ * the specified initial capacity, but with a reported size of 0. This method
84
+ * can be used to avoid needing to grow the underlying {@link ByteBank}.
85
+ *
86
+ * @param name the name of this {@link Location}
87
+ */
88
+ public BytesLocation (final int initialCapacity , final String name ) {
66
89
this .bytes = new ByteArrayByteBank (initialCapacity );
90
+ this .name = name ;
67
91
}
68
92
69
93
/**
70
94
* Creates a {@link BytesLocation} backed by a {@link ByteArrayByteBank}
71
95
* that wraps the specified {@link ByteArray}.
72
96
*/
73
97
public BytesLocation (final ByteArray bytes ) {
98
+ this (bytes , null );
99
+ }
100
+
101
+ /**
102
+ * Creates a {@link BytesLocation} backed by a {@link ByteArrayByteBank} that
103
+ * wraps the specified {@link ByteArray}.
104
+ *
105
+ * @param name the name of this Location.
106
+ */
107
+ public BytesLocation (final ByteArray bytes , final String name ) {
74
108
this .bytes = new ByteArrayByteBank (bytes );
109
+ this .name = name ;
75
110
}
76
111
77
112
/**
@@ -81,7 +116,19 @@ public BytesLocation(final ByteArray bytes) {
81
116
* @param bytes the array to wrap
82
117
*/
83
118
public BytesLocation (final byte [] bytes ) {
119
+ this (bytes , null );
120
+ }
121
+
122
+ /**
123
+ * Creates a {@link BytesLocation} backed by a {@link ByteArrayByteBank} which
124
+ * wraps the specified array.
125
+ *
126
+ * @param bytes the array to wrap
127
+ * @param name the name of this Location.
128
+ */
129
+ public BytesLocation (final byte [] bytes , final String name ) {
84
130
this .bytes = new ByteArrayByteBank (bytes );
131
+ this .name = name ;
85
132
}
86
133
87
134
/**
@@ -92,11 +139,25 @@ public BytesLocation(final byte[] bytes) {
92
139
* @param offset the offset in the bytes array to start copying from
93
140
* @param length the number of bytes to copy, starting from the offset
94
141
*/
95
- public BytesLocation (final byte [] bytes , final int offset ,
96
- final int length )
142
+ public BytesLocation (final byte [] bytes , final int offset , final int length ) {
143
+ this (bytes , offset , length , null );
144
+ }
145
+
146
+ /**
147
+ * Creates a {@link BytesLocation} backed by a {@link ByteArrayByteBank} with
148
+ * the specified initial capacity and the provided data.
149
+ *
150
+ * @param bytes the bytes to copy into the new {@link BytesLocation}
151
+ * @param offset the offset in the bytes array to start copying from
152
+ * @param length the number of bytes to copy, starting from the offset
153
+ * @param name the name of this Location.
154
+ */
155
+ public BytesLocation (final byte [] bytes , final int offset , final int length ,
156
+ final String name )
97
157
{
98
158
this .bytes = new ByteArrayByteBank (length );
99
159
this .bytes .setBytes (0l , bytes , offset , length );
160
+ this .name = name ;
100
161
}
101
162
102
163
// -- BytesLocation methods --
@@ -106,6 +167,11 @@ public ByteBank getByteBank() {
106
167
return bytes ;
107
168
}
108
169
170
+ @ Override
171
+ public String getName () {
172
+ return name != null ? name : defaultName ();
173
+ }
174
+
109
175
// -- Object methods --
110
176
111
177
@ Override
0 commit comments