Skip to content

Commit cfd1b60

Browse files
committed
Merge branch '2.x' into 3.x
2 parents b56f872 + 12e23de commit cfd1b60

File tree

7 files changed

+933
-2
lines changed

7 files changed

+933
-2
lines changed

cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,14 +2589,14 @@ private final int _finishLongTextAscii(int len) throws JacksonException
25892589
{
25902590
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
25912591
final byte[] input = _inputBuffer;
2592+
int outPtr = 0;
25922593
while (len > 0) {
25932594
// load as much input as possible
25942595
int size = Math.min(len, Math.min(outBuf.length, input.length));
25952596
if (!_tryToLoadToHaveAtLeast(size)) {
25962597
return len;
25972598
}
2598-
int outEnd = size;
2599-
int outPtr = 0;
2599+
int outEnd = size + outPtr;
26002600
int inPtr = _inputPtr;
26012601
int i = 0;
26022602
// Tight loop to copy into the output buffer, bail if a non-ascii char is found
@@ -2614,9 +2614,11 @@ private final int _finishLongTextAscii(int len) throws JacksonException
26142614
_inputPtr = inPtr;
26152615
if (outPtr >= outBuf.length) {
26162616
outBuf = _textBuffer.finishCurrentSegment();
2617+
outPtr = 0;
26172618
}
26182619
len -= size;
26192620
}
2621+
_textBuffer.setCurrentLength(outPtr);
26202622
return len;
26212623
}
26222624

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tools.jackson.dataformat.cbor.parse;
2+
3+
4+
import java.io.IOException;
5+
import java.nio.charset.StandardCharsets;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
import tools.jackson.core.JsonParser;
10+
import tools.jackson.core.JsonToken;
11+
import tools.jackson.dataformat.cbor.CBORParser;
12+
import tools.jackson.dataformat.cbor.CBORTestBase;
13+
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
16+
public class ParseLongAsciiTextTest extends CBORTestBase
17+
{
18+
@Test
19+
public void testLongNonChunkedAsciiText() throws IOException {
20+
JsonParser p = cborFactory().createParser(this.getClass().getResourceAsStream("/data/macbeth-snippet-non-chunked.cbor"));
21+
22+
assertEquals(JsonToken.VALUE_STRING, p.nextToken());
23+
String expected = new String(readResource("/data/macbeth-snippet.txt"), "UTF-8");
24+
assertEquals(expected, p.getString());
25+
26+
}
27+
28+
@Test
29+
public void testLongChunkedAsciiText() throws IOException {
30+
JsonParser p = cborFactory().createParser(this.getClass().getResourceAsStream("/data/macbeth-snippet-chunked.cbor"));
31+
32+
assertEquals(JsonToken.VALUE_STRING, p.nextToken());
33+
String expected = new String(readResource("/data/macbeth-snippet.txt"), StandardCharsets.UTF_8);
34+
assertEquals(expected, p.getString());
35+
}
36+
37+
}
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
y�---
2+
Act I, Scene
3+
4+
A desert place.
5+
---
6+
7+
First Witch. When shall we three meet again
8+
In thunder, lightning, or in rain?
9+
Second Witch. When the hurlyburly's done,
10+
When the battle's lost and won.
11+
Third Witch. That will be ere the set of sun.
12+
First Witch. Where the place?
13+
Second Witch. Upon the heath.
14+
Third Witch. There to meet with Macbeth.
15+
First Witch. I come, Graymalkin!
16+
Second Witch. Paddock calls.
17+
Third Witch. Anon.
18+
All. Fair is foul, and foul is fair:
19+
Hover through the fog and filthy air.
20+
21+
---
22+
Act I, Scene
23+
24+
A camp near Forres.
25+
---
26+
27+
Duncan. What bloody man is that? He can report,
28+
As seemeth by his plight, of the revolt
29+
The newest state.
30+
Malcolm. This is the sergeant
31+
Who like a good and hardy soldier fought
32+
'Gainst my captivity. Hail, brave friend!
33+
Say to the king the knowledge of the broil
34+
As thou didst leave it.
35+
Sergeant. Doubtful it stood;
36+
As two spent swimmers, that do cling together
37+
And choke their art. The merciless Macdonwald-
38+
Worthy to be a rebel, for to that
39+
The multiplying villanies of nature
40+
Do swarm upon him-from the western isles
41+
Of kerns and gallowglasses is supplied;
42+
And fortune, on his damned quarrel smiling,
43+
Show'd like a rebel's whore: but all's too weak:
44+
For brave Macbeth-well he deserves that name-
45+
Disdaining fortune, with his brandish'd steel,
46+
Which smoked with bloody execution,
47+
Like valour's minion carved out his passage
48+
Till he faced the slave;
49+
Which ne'er shook hands, nor bade farewell to him,
50+
Till he unseam'd him from the nave to the chaps,
51+
And fix'd his head upon our battlements.
52+
Duncan. O valiant cousin! worthy gentleman!
53+
Sergeant. As whence the sun 'gins his reflection
54+
Shipwrecking storms and direful thunders break,
55+
So from that spring whence comfort seem'd to come
56+
Discomfort swells. Mark, king of Scotland, mark:
57+
No sooner justice had with valour arm'd
58+
Compell'd these skipping kerns to trust their heels,
59+
But the Norweyan lord surveying vantage,
60+
With furbish'd arms and new supplies of men
61+
Began a fresh assault.
62+
Duncan. Dismay'd not this
63+
Our captains, Macbeth and Banquo?
64+
Sergeant. Yes;
65+
As sparrows eagles, or the hare the lion.
66+
If I say sooth, I must report they were
67+
As cannons overcharged with double cracks, so they
68+
Doubly redoubled strokes upon the foe:
69+
Except they meant to bathe in reeking wounds,
70+
Or memorise another Golgotha,
71+
I cannot tell.
72+
But I am faint, my gashes cry for help.
73+
Duncan. So well thy words become thee as thy wounds;
74+
They smack of honour both. Go get him surgeons.
75+
[Exit Sergeant, attended]
76+
Who comes here?
77+
[Enter ROSS]
78+
79+
Malcolm. The worthy thane of Ross.
80+
Lennox. What a haste looks through his eyes! So should he look
81+
That seems to speak things strange.
82+
Ross. God save the king!
83+
Duncan. Whence camest thou, worthy thane?
84+
Ross. From Fife, great king;
85+
Where the Norweyan banners flout the sky
86+
And fan our people cold. Norway himself,
87+
With terrible numbers,
88+
Assisted by that most disloyal traitor
89+
The thane of Cawdor, began a dismal conflict;
90+
Till that Bellona's bridegroom, lapp'd in proof,
91+
Confronted him with self-comparisons,
92+
Point against point rebellious, arm 'gainst arm.
93+
Curbing his lavish spirit: and, to conclude,
94+
The victory fell on us.
95+
Duncan. Great happiness!
96+
Ross. That now
97+
Sweno, the Norways' king, craves composition:
98+
Nor would we deign him burial of his men
99+
Till he disbursed at Saint Colme's inch
100+
Ten thousand dollars to our general use.
101+
Duncan. No more that thane of Cawdor shall deceive
102+
Our bosom interest: go pronounce his present death,
103+
And with his former title greet Macbeth.
104+
Ross. I'll see it done.
105+
Duncan. What he hath lost noble Macbeth hath won.
106+
[Exeunt]
107+
108+
---
109+
Act I, Scene
110+
111+
A heath near Forres.
112+
113+
---
114+
[Thunder. Enter the three Witches]
115+
116+
First Witch. Where hast thou been, sister?
117+
Second Witch. Killing swine.
118+
Third Witch. Sister, where thou?
119+
First Witch. A sailor's wife had chestnuts in her lap,
120+
And munch'd, and munch'd, and munch'd:-
121+
'Give me,' quoth I:
122+
'Aroint thee, witch!' the rump-fed ronyon cries.
123+
Her husband's to Aleppo gone, master o' the Tiger:
124+
Buty� in a sieve I'll thither sail,
125+
And, like a rat without a tail,
126+
I'll do, I'll do, and I'll do.
127+
Second Witch. I'll give thee a wind.
128+
First Witch. Thou'rt kind.
129+
Third Witch. And I another.
130+
First Witch. I myself have all the other,
131+
And the very ports they blow,
132+
All the quarters that they know
133+
I' the shipman's card.
134+
I will drain him dry as hay:
135+
Sleep shall neither night nor day
136+
Hang upon his pent-house lid;
137+
He shall live a man forbid:
138+
Weary se'nnights nine times nine
139+
Shall he dwindle, peak and pine:
140+
Though his bark cannot be lost,
141+
Yet it shall be tempest-tost.
142+
Look what I have.
143+
Second Witch. Show me, show me.
144+
First Witch. Here I have a pilot's thumb,
145+
Wreck'd as homeward he did come.
146+
[Drum within]
147+
148+
Third Witch. A drum, a drum!
149+
Macbeth doth come.
150+
All. The weird sisters, hand in hand,
151+
Posters of the sea and land,
152+
Thus do go about, about:
153+
Thrice to thine and thrice to mine
154+
And thrice again, to make up nine.
155+
Peace! the charm's wound up.
156+
[Enter MACBETH and BANQUO]
157+
158+
Macbeth. So foul and fair a day I have not seen.
159+
Banquo. How far is't call'd to Forres? What are these
160+
So wither'd and so wild in their attire,
161+
That look not like the inhabitants o' the earth,
162+
And yet are on't? Live you? or are you aught
163+
That man may question? You seem to understand me,
164+
By each at once her chappy finger laying
165+
Upon her skinny lips: you should be women,
166+
And yet your beards forbid me to interpret
167+
That you are so.
168+
Macbeth. Speak, if you can: what are you?
169+
First Witch. All hail, Macbeth! hail to thee, thane of Glamis!
170+
Second Witch. All hail, Macbeth, hail to thee, thane of Cawdor!
171+
Third Witch. All hail, Macbeth, thou shalt be king hereafter!
172+
Banquo. Good sir, why do you start; and seem to fear
173+
Things that do sound so fair? I' the name of truth,
174+
Are ye fantastical, or that indeed
175+
Which outwardly ye show? My noble partner
176+
You greet with present grace and great prediction
177+
Of noble having and of royal hope,
178+
That he seems rapt withal: to me you speak not.
179+
If you can look into the seeds of time,
180+
And say which grain will grow and which will not,
181+
Speak then to me, who neither beg nor fear
182+
Your favours nor your hate.
183+
First Witch. Hail!
184+
Second Witch. Hail!
185+
Third Witch. Hail!
186+
First Witch. Lesser than Macbeth, and greater.
187+
Second Witch. Not so happy, yet much happier.
188+
Third Witch. Thou shalt get kings, though thou be none:
189+
So all hail, Macbeth and Banquo!
190+
First Witch. Banquo and Macbeth, all hail!
191+
Macbeth. Stay, you imperfect speakers, tell me more:
192+
By Sinel's death I know I am thane of Glamis;
193+
But how of Cawdor? the thane of Cawdor lives,
194+
A prosperous gentleman; and to be king
195+
Stands not within the prospect of belief,
196+
No more than to be Cawdor. Say from whence
197+
You owe this strange intelligence? or why
198+
Upon this blasted heath you stop our way
199+
With such prophetic greeting? Speak, I charge you.
200+
[Witches vanish]
201+
202+
Banquo. The earth hath bubbles, as the water has,
203+
And these are of them. Whither are they vanish'd?
204+
Macbeth. Into the air; and what seem'd corporal melted
205+
As breath into the wind. Would they had stay'd!
206+
Banquo. Were such things here as we do speak about?
207+
Or have we eaten on the insane root
208+
That takes the reason prisoner?
209+
Macbeth. Your children shall be kings.
210+
Banquo. You shall be king.
211+
Macbeth. And thane of Cawdor too: went it not so?
212+
Banquo. To the selfsame tune and words. Who's here?
213+
[Enter ROSS and ANGUS]
214+
215+
Ross. The king hath happily received, Macbeth,
216+
The news of thy success; and when he reads
217+
Thy personal venture in the rebels' fight,
218+
His wonders and his praises do contend
219+
Which should be thine or his: silenced with that,
220+
In viewing o'er the rest o' the selfsame day,
221+
He finds thee in the stout Norweyan ranks,
222+
Nothing afeard of what thyself didst make,
223+
Strange images of death. As thick as hail
224+
Came post with post; and every one did bear
225+
Thy praises in his kingdom's great defence,
226+
And pour'd them down before him.
227+
Angus. We are sent
228+
To give thee from our royal master thanks;
229+
Only to herald thee into his sight,
230+
Not pay thee.
231+
Ross. And, for an eary �nest of a greater honour,
232+
He bade me, from him, call thee thane of Cawdor:
233+
In which addition, hail, most worthy thane!
234+
For it is thine.
235+
Banquo. What, can the devil speak true?
236+
Macbeth. The thane of Cawdor lives: why do you dress me
237+
In borrow'd robes?
238+
Angus. Who was the thane lives yet;
239+
But under heavy judgment bears that life
240+
Which he deserves to lose. Whether he was combined
241+
With those of Norway, or did line the rebel
242+
With hidden help and vantage, or that with both
243+
He labour'd in his country's wreck, I know not;
244+
But treasons capital, confess'd and proved,
245+
Have overthrown him.
246+
Macbeth. [Aside] Glamis, and thane of Cawdor!
247+
The greatest is behind.
248+
[To ROSS and ANGUS]
249+
Thanks for your pains.
250+
[To BANQUO]
251+
Do you not hope your children shall be kings,
252+
When those that gave the thane of Cawdor to me
253+
Promised no less to them?
254+
Banquo. That trusted home
255+
Might yet enkindle you unto the crown,
256+
Besides the thane of Cawdor. But 'tis strange:
257+
And oftentimes, to win us to our harm,
258+
The instruments of darkness tell us truths,
259+
Win us with honest trifles, to betray's
260+
In deepest consequence.
261+
Cousins, a word, I pray you.
262+
Macbeth. [Aside]. Two truths are told,
263+
As happy prologues to the swelling act
264+
Of the imperial theme.-I thank you, gentlemen.
265+
[Aside] This supernatural soliciting]
266+
Cannot be ill, cannot be good: if ill,
267+
Why hath it given me earnest of success,
268+
Commencing in a truth? I am thane of Cawdor:
269+
If good, why do I yield to that suggestion
270+
Whose horrid image doth unfix my hair
271+
And make my seated heart knock at my ribs,
272+
Against the use of nature? Present fears
273+
Are less than horrible imaginings:
274+
My thought, whose murder yet is but fantastical,
275+
Shakes so my single state of man that function
276+
Is smother'd in surmise, and nothing is
277+
But what is not.
278+
Banquo. Look, how our partner's rapt.
279+
Macbeth. [Aside] If chance will have me king, why, chance may crown me,
280+
Without my stir.
281+
Banquo. New horrors come upon him,
282+
Like our strange garments, cleave not to their mould
283+
But with the aid of use.
284+
Macbeth. [Aside] Come what come may,
285+
Time and the hour runs through the roughest day.
286+
Banquo. Worthy Macbeth, we stay upon your leisure.
287+
Macbeth. Give me your favour: my dull brain was wrought
288+
With things forgotten. Kind gentlemen, your pains
289+
Are register'd where every day I turn
290+
The leaf to read them. Let us toward the king.
291+
Think upon what hath chanced, and, at more time,
292+
The interim having weigh'd it, let us speak
293+
Our free hearts each to other.
294+
Banquo. Very gladly.
295+
Macbeth. Till then, enough. Come, friends.
296+

0 commit comments

Comments
 (0)