nokogiri 1.5.2-java → 1.5.3-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data/CHANGELOG.ja.rdoc +35 -0
- data/CHANGELOG.rdoc +37 -2
- data/Manifest.txt +11 -3
- data/README.rdoc +1 -1
- data/ROADMAP.md +86 -0
- data/{nokogiri_help_responses.md → STANDARD_RESPONSES.md} +11 -4
- data/Y_U_NO_GEMSPEC.md +155 -0
- data/build_all +58 -0
- data/ext/java/nokogiri/HtmlDocument.java +10 -1
- data/ext/java/nokogiri/XmlAttr.java +11 -1
- data/ext/java/nokogiri/XmlDocument.java +4 -0
- data/ext/java/nokogiri/XmlNamespace.java +25 -0
- data/ext/java/nokogiri/XmlNode.java +6 -6
- data/ext/java/nokogiri/XmlReader.java +19 -4
- data/ext/java/nokogiri/XmlSaxPushParser.java +88 -57
- data/ext/java/nokogiri/XmlSyntaxError.java +15 -3
- data/ext/java/nokogiri/XmlXpathContext.java +3 -3
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +2 -1
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +89 -1
- data/ext/java/nokogiri/internals/ParserContext.java +23 -2
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +18 -1
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +2 -3
- data/ext/nokogiri/extconf.rb +1 -1
- data/ext/nokogiri/xml_io.c +1 -1
- data/ext/nokogiri/xml_namespace.c +0 -6
- data/ext/nokogiri/xml_node.c +11 -11
- data/ext/nokogiri/xml_node_set.c +1 -1
- data/ext/nokogiri/xml_xpath_context.c +20 -16
- data/ext/nokogiri/xml_xpath_context.h +1 -0
- data/ext/nokogiri/xslt_stylesheet.c +7 -64
- data/lib/nokogiri/css/node.rb +3 -0
- data/lib/nokogiri/css/parser.rb +244 -203
- data/lib/nokogiri/css/parser.y +20 -2
- data/lib/nokogiri/css/xpath_visitor.rb +2 -2
- data/lib/nokogiri/html/document.rb +2 -1
- data/lib/nokogiri/html/element_description_defaults.rb +1 -1
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml/document.rb +1 -1
- data/lib/nokogiri/xml/parse_options.rb +2 -2
- data/lib/nokogiri/xml/sax/document.rb +1 -1
- data/lib/nokogiri/xml/sax/parser.rb +1 -1
- data/lib/nokogiri/xslt.rb +1 -1
- data/test/css/test_parser.rb +38 -0
- data/test/files/to_be_xincluded.xml +2 -0
- data/test/files/xinclude.xml +4 -0
- data/test/helper.rb +18 -45
- data/test/html/sax/test_parser.rb +5 -3
- data/test/html/sax/test_parser_context.rb +8 -10
- data/test/html/test_document.rb +19 -5
- data/test/html/test_node.rb +2 -4
- data/test/test_reader.rb +63 -0
- data/test/test_xslt_transforms.rb +3 -1
- data/test/xml/sax/test_parser_context.rb +10 -17
- data/test/xml/sax/test_push_parser.rb +1 -0
- data/test/xml/test_attr.rb +5 -6
- data/test/xml/test_builder.rb +5 -6
- data/test/xml/test_cdata.rb +1 -3
- data/test/xml/test_document.rb +11 -14
- data/test/xml/test_document_encoding.rb +3 -1
- data/test/xml/test_document_fragment.rb +27 -8
- data/test/xml/test_node.rb +21 -0
- data/test/xml/test_node_set.rb +2 -2
- data/test/xml/test_text.rb +1 -3
- data/test/xml/test_unparented_node.rb +2 -2
- data/test/xml/test_xpath.rb +15 -6
- data/test/xslt/test_custom_functions.rb +35 -0
- data/test_all +84 -0
- metadata +13 -8
- data/ext/java/nokogiri/internals/PushInputStream.java +0 -411
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: nokogiri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.5.
|
5
|
+
version: 1.5.3
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Aaron Patterson
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2012-
|
15
|
+
date: 2012-06-01 00:00:00 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: hoe-bundler
|
@@ -193,11 +193,16 @@ files:
|
|
193
193
|
- .gemtest
|
194
194
|
- CHANGELOG.ja.rdoc
|
195
195
|
- CHANGELOG.rdoc
|
196
|
+
- C_CODING_STYLE.rdoc
|
196
197
|
- Manifest.txt
|
197
198
|
- README.ja.rdoc
|
198
199
|
- README.rdoc
|
200
|
+
- ROADMAP.md
|
199
201
|
- Rakefile
|
202
|
+
- STANDARD_RESPONSES.md
|
203
|
+
- Y_U_NO_GEMSPEC.md
|
200
204
|
- bin/nokogiri
|
205
|
+
- build_all
|
201
206
|
- ext/java/nokogiri/EncodingHandler.java
|
202
207
|
- ext/java/nokogiri/HtmlDocument.java
|
203
208
|
- ext/java/nokogiri/HtmlElementDescription.java
|
@@ -244,7 +249,6 @@ files:
|
|
244
249
|
- ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java
|
245
250
|
- ext/java/nokogiri/internals/NokogiriXsltErrorListener.java
|
246
251
|
- ext/java/nokogiri/internals/ParserContext.java
|
247
|
-
- ext/java/nokogiri/internals/PushInputStream.java
|
248
252
|
- ext/java/nokogiri/internals/ReaderNode.java
|
249
253
|
- ext/java/nokogiri/internals/SaveContextVisitor.java
|
250
254
|
- ext/java/nokogiri/internals/SchemaErrorHandler.java
|
@@ -389,7 +393,6 @@ files:
|
|
389
393
|
- lib/nokogiri/xslt/stylesheet.rb
|
390
394
|
- lib/xercesImpl.jar
|
391
395
|
- lib/xsd/xmlparser/nokogiri.rb
|
392
|
-
- nokogiri_help_responses.md
|
393
396
|
- tasks/cross_compile.rb
|
394
397
|
- tasks/nokogiri.org.rb
|
395
398
|
- tasks/test.rb
|
@@ -419,7 +422,9 @@ files:
|
|
419
422
|
- test/files/staff.xml
|
420
423
|
- test/files/staff.xslt
|
421
424
|
- test/files/tlm.html
|
425
|
+
- test/files/to_be_xincluded.xml
|
422
426
|
- test/files/valid_bar.xml
|
427
|
+
- test/files/xinclude.xml
|
423
428
|
- test/helper.rb
|
424
429
|
- test/html/sax/test_parser.rb
|
425
430
|
- test/html/sax/test_parser_context.rb
|
@@ -447,6 +452,7 @@ files:
|
|
447
452
|
- test/xml/test_attr.rb
|
448
453
|
- test/xml/test_attribute_decl.rb
|
449
454
|
- test/xml/test_builder.rb
|
455
|
+
- test/xml/test_c14n.rb
|
450
456
|
- test/xml/test_cdata.rb
|
451
457
|
- test/xml/test_comment.rb
|
452
458
|
- test/xml/test_document.rb
|
@@ -462,9 +468,9 @@ files:
|
|
462
468
|
- test/xml/test_node.rb
|
463
469
|
- test/xml/test_node_attributes.rb
|
464
470
|
- test/xml/test_node_encoding.rb
|
471
|
+
- test/xml/test_node_inheritance.rb
|
465
472
|
- test/xml/test_node_reparenting.rb
|
466
473
|
- test/xml/test_node_set.rb
|
467
|
-
- test/xml/test_node_inheritance.rb
|
468
474
|
- test/xml/test_parse_options.rb
|
469
475
|
- test/xml/test_processing_instruction.rb
|
470
476
|
- test/xml/test_reader_encoding.rb
|
@@ -473,12 +479,11 @@ files:
|
|
473
479
|
- test/xml/test_syntax_error.rb
|
474
480
|
- test/xml/test_text.rb
|
475
481
|
- test/xml/test_unparented_node.rb
|
482
|
+
- test/xml/test_xinclude.rb
|
476
483
|
- test/xml/test_xpath.rb
|
477
484
|
- test/xslt/test_custom_functions.rb
|
478
485
|
- test/xslt/test_exception_handling.rb
|
479
|
-
-
|
480
|
-
- test/xml/test_xinclude.rb
|
481
|
-
- C_CODING_STYLE.rdoc
|
486
|
+
- test_all
|
482
487
|
- lib/nokogiri/nokogiri.jar
|
483
488
|
homepage: http://nokogiri.org
|
484
489
|
licenses: []
|
@@ -1,411 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* (The MIT License)
|
3
|
-
*
|
4
|
-
* Copyright (c) 2008 - 2011:
|
5
|
-
*
|
6
|
-
* * {Aaron Patterson}[http://tenderlovemaking.com]
|
7
|
-
* * {Mike Dalessio}[http://mike.daless.io]
|
8
|
-
* * {Charles Nutter}[http://blog.headius.com/]
|
9
|
-
* * {Sergio Arbeo}[http://www.serabe.com/]
|
10
|
-
* * {Patrick Mahoney}[http://polycrystal.org/]
|
11
|
-
* * {Yoko Harada}[http://yokolet.blogspot.com/]
|
12
|
-
*
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
14
|
-
* a copy of this software and associated documentation files (the
|
15
|
-
* 'Software'), to deal in the Software without restriction, including
|
16
|
-
* without limitation the rights to use, copy, modify, merge, publish,
|
17
|
-
* distribute, sublicense, and/or sell copies of the Software, and to
|
18
|
-
* permit persons to whom the Software is furnished to do so, subject to
|
19
|
-
* the following conditions:
|
20
|
-
*
|
21
|
-
* The above copyright notice and this permission notice shall be
|
22
|
-
* included in all copies or substantial portions of the Software.
|
23
|
-
*
|
24
|
-
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
25
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
27
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
28
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
29
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
30
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
-
*/
|
32
|
-
|
33
|
-
package nokogiri.internals;
|
34
|
-
|
35
|
-
import java.io.IOException;
|
36
|
-
import java.io.InputStream;
|
37
|
-
import java.nio.channels.ClosedChannelException;
|
38
|
-
import java.util.ArrayList;
|
39
|
-
|
40
|
-
|
41
|
-
/**
|
42
|
-
* Implements a "push" InputStream. An owner thread create an
|
43
|
-
* InputStream and passes it to a second thread. The owner thread
|
44
|
-
* calls PushInputStream.write() to write data to the stream. The
|
45
|
-
* second thread calls PushInputStream.read() and other InputStream
|
46
|
-
* methods.
|
47
|
-
*
|
48
|
-
* You should ensure that only one thread write to, and only one
|
49
|
-
* thread reads to, this stream, though nothing enforces this
|
50
|
-
* strictly.
|
51
|
-
*/
|
52
|
-
public class PushInputStream extends InputStream {
|
53
|
-
/**
|
54
|
-
* Current position in the stream relative to the start of the
|
55
|
-
* buffer.
|
56
|
-
*/
|
57
|
-
protected int pos;
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Current mark position, or -1 if there is no mark.
|
61
|
-
*/
|
62
|
-
protected int mark;
|
63
|
-
|
64
|
-
protected int readlimit;
|
65
|
-
|
66
|
-
/**
|
67
|
-
* State is open or closed.
|
68
|
-
*/
|
69
|
-
protected boolean isOpen;
|
70
|
-
|
71
|
-
protected Buffer buffer;
|
72
|
-
|
73
|
-
public PushInputStream() {
|
74
|
-
pos = 0;
|
75
|
-
mark = -1;
|
76
|
-
readlimit = -1;
|
77
|
-
isOpen = true;
|
78
|
-
|
79
|
-
buffer = new Buffer(512);
|
80
|
-
}
|
81
|
-
|
82
|
-
protected synchronized void ensureOpen() throws IOException {
|
83
|
-
if (!isOpen) {
|
84
|
-
throw new ClosedChannelException();
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* Write data that can be read from the stream.
|
90
|
-
*/
|
91
|
-
public synchronized void write(byte[] b) {
|
92
|
-
if (buffer == null) System.out.println("BUFFER IS NULL");
|
93
|
-
if (b == null) System.out.println("BYTE ARRAY IS NILL");
|
94
|
-
buffer.put(b);
|
95
|
-
notifyAll(); // notify readers waiting
|
96
|
-
}
|
97
|
-
|
98
|
-
/**
|
99
|
-
* Write data and then wait until all the data has been read
|
100
|
-
* (waits until the thread reading from this stream is blocked in
|
101
|
-
* a read()).
|
102
|
-
*/
|
103
|
-
public synchronized void writeAndWaitForRead(byte[] b) throws IOException {
|
104
|
-
ensureOpen();
|
105
|
-
write(b);
|
106
|
-
for (;;) {
|
107
|
-
try {
|
108
|
-
wait();
|
109
|
-
break;
|
110
|
-
} catch (InterruptedException e) {
|
111
|
-
// continue waiting
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
/*
|
117
|
-
*------------------------------------------------------------
|
118
|
-
* InputStream methods
|
119
|
-
*------------------------------------------------------------
|
120
|
-
*/
|
121
|
-
|
122
|
-
/**
|
123
|
-
* @see InputStream.available()
|
124
|
-
*/
|
125
|
-
@Override
|
126
|
-
public synchronized int available() throws IOException {
|
127
|
-
ensureOpen();
|
128
|
-
return buffer.size() - pos;
|
129
|
-
}
|
130
|
-
|
131
|
-
int nClose = 0;
|
132
|
-
/**
|
133
|
-
* @see InputStream.close()
|
134
|
-
*/
|
135
|
-
@Override
|
136
|
-
public synchronized void close() throws IOException {
|
137
|
-
if (!isOpen) return;
|
138
|
-
isOpen = false;
|
139
|
-
buffer = null;
|
140
|
-
notifyAll();
|
141
|
-
}
|
142
|
-
|
143
|
-
/**
|
144
|
-
* @see InputStream.mark()
|
145
|
-
*/
|
146
|
-
@Override
|
147
|
-
public synchronized void mark(int readlimit) {
|
148
|
-
this.mark = pos;
|
149
|
-
this.readlimit = readlimit;
|
150
|
-
}
|
151
|
-
|
152
|
-
/**
|
153
|
-
* Mark the current position in this stream. Supported by
|
154
|
-
* PushInputStream.
|
155
|
-
*
|
156
|
-
* @see InputStream.markSupported()
|
157
|
-
*/
|
158
|
-
@Override
|
159
|
-
public synchronized boolean markSupported() {
|
160
|
-
return true;
|
161
|
-
}
|
162
|
-
|
163
|
-
/**
|
164
|
-
* @see InputStream.read()
|
165
|
-
*/
|
166
|
-
@Override
|
167
|
-
public synchronized int read() throws IOException {
|
168
|
-
ensureOpen();
|
169
|
-
byte[] b = new byte[1];
|
170
|
-
read(b, 0, 1);
|
171
|
-
return (int) b[0];
|
172
|
-
}
|
173
|
-
|
174
|
-
/**
|
175
|
-
* @see InputStream.read(byte[])
|
176
|
-
*/
|
177
|
-
@Override
|
178
|
-
public synchronized int read(byte[] b) throws IOException {
|
179
|
-
ensureOpen();
|
180
|
-
return read(b, 0, b.length);
|
181
|
-
}
|
182
|
-
|
183
|
-
protected synchronized boolean markIsValid() {
|
184
|
-
return (mark >= 0 && pos < mark+readlimit);
|
185
|
-
}
|
186
|
-
|
187
|
-
/**
|
188
|
-
* @see InputStream.read(byte[], int, int)
|
189
|
-
*/
|
190
|
-
@Override
|
191
|
-
public synchronized int read(byte[] b, int off, int len) throws IOException {
|
192
|
-
while (isOpen && available() == 0) {
|
193
|
-
/* block until data available */
|
194
|
-
try {
|
195
|
-
notifyAll(); // notify writers waiting
|
196
|
-
wait();
|
197
|
-
} catch (InterruptedException e) {
|
198
|
-
// continue waiting
|
199
|
-
}
|
200
|
-
}
|
201
|
-
|
202
|
-
if (!isOpen) {
|
203
|
-
return -1;
|
204
|
-
}
|
205
|
-
|
206
|
-
int readLen = Math.min(available(), len);
|
207
|
-
|
208
|
-
buffer.get(pos, readLen, b, off);
|
209
|
-
pos += readLen;
|
210
|
-
|
211
|
-
int reduce;
|
212
|
-
|
213
|
-
if (markIsValid()) {
|
214
|
-
reduce = mark;
|
215
|
-
} else {
|
216
|
-
reduce = pos;
|
217
|
-
}
|
218
|
-
|
219
|
-
buffer.truncateFromStart(buffer.size - reduce);
|
220
|
-
pos -= reduce;
|
221
|
-
mark -= reduce;
|
222
|
-
if (mark < 0) mark = -1; // don't wrap mark around?
|
223
|
-
|
224
|
-
return readLen;
|
225
|
-
}
|
226
|
-
|
227
|
-
/**
|
228
|
-
* @see InputStream.reset()
|
229
|
-
*/
|
230
|
-
@Override
|
231
|
-
public synchronized void reset() throws IOException {
|
232
|
-
ensureOpen();
|
233
|
-
if (markIsValid())
|
234
|
-
pos = mark;
|
235
|
-
}
|
236
|
-
|
237
|
-
/**
|
238
|
-
* @see InputStream.skip()
|
239
|
-
*/
|
240
|
-
@Override
|
241
|
-
public synchronized long skip(long n) throws IOException {
|
242
|
-
ensureOpen();
|
243
|
-
pos += n;
|
244
|
-
return n;
|
245
|
-
}
|
246
|
-
|
247
|
-
/*
|
248
|
-
*------------------------------------------------------------
|
249
|
-
* Data Buffer
|
250
|
-
*------------------------------------------------------------
|
251
|
-
*/
|
252
|
-
|
253
|
-
public static class Block {
|
254
|
-
protected byte[] data;
|
255
|
-
|
256
|
-
public Block(int size) {
|
257
|
-
data = new byte[size];
|
258
|
-
}
|
259
|
-
|
260
|
-
public void copyIn(byte[] src, int srcPos, int destPos, int length) {
|
261
|
-
System.arraycopy(src, srcPos, data, destPos, length);
|
262
|
-
}
|
263
|
-
|
264
|
-
public void copyOut(int srcPos, byte[] dest, int destPos, int length) {
|
265
|
-
System.arraycopy(data, srcPos, dest, destPos, length);
|
266
|
-
}
|
267
|
-
}
|
268
|
-
|
269
|
-
public static class BlockList extends ArrayList<Block> {
|
270
|
-
public BlockList() {
|
271
|
-
super();
|
272
|
-
}
|
273
|
-
|
274
|
-
@Override
|
275
|
-
public void removeRange(int fromIndex, int toIndex) {
|
276
|
-
super.removeRange(fromIndex, toIndex);
|
277
|
-
}
|
278
|
-
}
|
279
|
-
|
280
|
-
public static class Buffer {
|
281
|
-
protected int blockSize;
|
282
|
-
protected BlockList blocks;
|
283
|
-
|
284
|
-
/**
|
285
|
-
* Offset (position) to the first logical byte in the buffer.
|
286
|
-
*/
|
287
|
-
protected int offset;
|
288
|
-
|
289
|
-
/**
|
290
|
-
* Logical size of the buffer.
|
291
|
-
*/
|
292
|
-
protected int size;
|
293
|
-
|
294
|
-
public Buffer(int blockSize) {
|
295
|
-
this.blockSize = blockSize;
|
296
|
-
this.blocks = new BlockList();
|
297
|
-
this.offset = 0;
|
298
|
-
this.size = 0;
|
299
|
-
}
|
300
|
-
|
301
|
-
public int size() {
|
302
|
-
return size;
|
303
|
-
}
|
304
|
-
|
305
|
-
protected class Segment {
|
306
|
-
/**
|
307
|
-
* Block index.
|
308
|
-
*/
|
309
|
-
protected int block;
|
310
|
-
|
311
|
-
/**
|
312
|
-
* Offset into the block.
|
313
|
-
*/
|
314
|
-
protected int off;
|
315
|
-
|
316
|
-
/**
|
317
|
-
* Length of segment.
|
318
|
-
*/
|
319
|
-
protected int len;
|
320
|
-
|
321
|
-
/**
|
322
|
-
* Calculate the block number and block offset given a position.
|
323
|
-
*/
|
324
|
-
protected Segment(int pos) {
|
325
|
-
int absPos = offset + pos;
|
326
|
-
block = (int) (absPos / blockSize);
|
327
|
-
off = (int) (absPos % blockSize);
|
328
|
-
len = -1;
|
329
|
-
}
|
330
|
-
}
|
331
|
-
|
332
|
-
protected Segment[] accessList(int pos, int size) {
|
333
|
-
Segment start = new Segment(pos);
|
334
|
-
Segment end = new Segment(pos + size);
|
335
|
-
int nBlocks = end.block - start.block + 1;
|
336
|
-
Segment[] segs = new Segment[nBlocks];
|
337
|
-
|
338
|
-
start.len = Math.min(size, blockSize - start.off);
|
339
|
-
segs[0] = start;
|
340
|
-
int currPos = pos + start.len;
|
341
|
-
int currSize = start.len;
|
342
|
-
for (int i = 1; i < nBlocks; i++) {
|
343
|
-
Segment seg = new Segment(currPos);
|
344
|
-
seg.len = Math.min(blockSize, size - currSize);
|
345
|
-
segs[i] = seg;
|
346
|
-
currPos += seg.len;
|
347
|
-
currSize += seg.len;
|
348
|
-
}
|
349
|
-
|
350
|
-
return segs;
|
351
|
-
}
|
352
|
-
|
353
|
-
protected void ensureCapacity(int pos) {
|
354
|
-
Segment seg = new Segment(pos-1);
|
355
|
-
|
356
|
-
while (blocks.size() < (seg.block + 1))
|
357
|
-
blocks.add(new Block(blockSize));
|
358
|
-
}
|
359
|
-
|
360
|
-
public void put(byte b) {
|
361
|
-
byte[] buf = new byte[1];
|
362
|
-
buf[0] = b;
|
363
|
-
put(buf);
|
364
|
-
}
|
365
|
-
|
366
|
-
public void put(byte[] b) {
|
367
|
-
ensureCapacity(size + b.length);
|
368
|
-
Segment[] segs = accessList(size, b.length);
|
369
|
-
|
370
|
-
int off = 0;
|
371
|
-
for (int i = 0; i < segs.length; i++) {
|
372
|
-
Block block = blocks.get(segs[i].block);
|
373
|
-
block.copyIn(b, off, segs[i].off, segs[i].len);
|
374
|
-
}
|
375
|
-
|
376
|
-
size += b.length;
|
377
|
-
}
|
378
|
-
|
379
|
-
public byte[] get(int pos, int len) {
|
380
|
-
byte[] b = new byte[len];
|
381
|
-
get(pos, len, b, 0);
|
382
|
-
return b;
|
383
|
-
}
|
384
|
-
|
385
|
-
/**
|
386
|
-
* Throws IndexOutOfBoundsException.
|
387
|
-
*/
|
388
|
-
public void get(int pos, int len, byte[] b, int off) {
|
389
|
-
Segment[] segs = accessList(pos, len);
|
390
|
-
for (int i = 0; i < segs.length; i++) {
|
391
|
-
Block block = blocks.get(segs[i].block);
|
392
|
-
block.copyOut(segs[i].off, b, off, segs[i].len);
|
393
|
-
}
|
394
|
-
}
|
395
|
-
|
396
|
-
/**
|
397
|
-
* Truncate the buffer to <code>newSize</code> by removing
|
398
|
-
* data from the start of the buffer.
|
399
|
-
*/
|
400
|
-
public void truncateFromStart(int newSize) {
|
401
|
-
if (newSize > size || newSize < 0)
|
402
|
-
throw new RuntimeException("invalid size");
|
403
|
-
|
404
|
-
Segment newStart = new Segment(size - newSize);
|
405
|
-
blocks.removeRange(0, newStart.block);
|
406
|
-
|
407
|
-
size = newSize;
|
408
|
-
offset = newStart.off;
|
409
|
-
}
|
410
|
-
}
|
411
|
-
}
|