Skip to content

Commit 1fd4648

Browse files
committed
Minor cleanup for skeletal non-blocking/smile parser, to prepare for implementation
1 parent cce1294 commit 1fd4648

File tree

6 files changed

+62
-34
lines changed

6 files changed

+62
-34
lines changed

avro/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ abstractions.
2525
<dependency>
2626
<groupId>com.fasterxml.jackson.core</groupId>
2727
<artifactId>jackson-databind</artifactId>
28-
<version>${version.jackson.core}</version>
2928
</dependency>
3029
<dependency>
3130
<groupId>org.apache.avro</groupId>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fasterxml.jackson.dataformat.smile.async;
2+
3+
import java.io.IOException;
4+
5+
public interface NonBlockingByteArrayFeeder extends NonBlockingInputFeeder
6+
{
7+
/**
8+
* Method that can be called to feed more data, if (and only if)
9+
* {@link #needMoreInput} returns true.
10+
*
11+
* @param data Byte array that contains data to feed: caller must ensure data remains
12+
* stable until it is fully processed (which is true when {@link #needMoreInput}
13+
* returns true)
14+
* @param offset Offset within array where input data to process starts
15+
* @param len Length of input data within array to process.
16+
*
17+
* @throws IOException if the state is such that this method should not be called
18+
* (has not yet consumed existing input data, or has been marked as closed)
19+
*/
20+
public void feedInput(byte[] data, int offset, int len) throws IOException;
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.fasterxml.jackson.dataformat.smile.async;
2+
3+
import java.io.IOException;
4+
import java.nio.ByteBuffer;
5+
6+
public interface NonBlockingByteBufferFeeder extends NonBlockingInputFeeder
7+
{
8+
/**
9+
* Method that can be called to feed more data, if (and only if)
10+
* {@link NonBlockingInputFeeder#needMoreInput} returns true.
11+
*
12+
* @param buffer Buffer that contains additional input to read
13+
*
14+
* @throws IOException if the state is such that this method should not be called
15+
* (has not yet consumed existing input data, or has been marked as closed)
16+
*/
17+
public void feedInput(ByteBuffer buffer) throws IOException;
18+
}

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingInputFeeder.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.fasterxml.jackson.dataformat.smile.async;
22

3-
import java.io.IOException;
4-
53
/**
64
* Interface used by non-blocking {@link com.fasterxml.jackson.core.JsonParser}
75
* to get more input to parse.
@@ -23,24 +21,9 @@ public interface NonBlockingInputFeeder
2321
*/
2422
public boolean needMoreInput();
2523

26-
/**
27-
* Method that can be called to feed more data, if (and only if)
28-
* {@link #needMoreInput} returns true.
29-
*
30-
* @param data Byte array that contains data to feed: caller must ensure data remains
31-
* stable until it is fully processed (which is true when {@link #needMoreInput}
32-
* returns true)
33-
* @param offset Offset within array where input data to process starts
34-
* @param len Length of input data within array to process.
35-
*
36-
* @throws IOException if the state is such that this method should not be called
37-
* (has not yet consumed existing input data, or has been marked as closed)
38-
*/
39-
public void feedInput(byte[] data, int offset, int len) throws IOException;
40-
4124
/**
4225
* Method that should be called after last chunk of data to parse has been fed
43-
* (with {@link #feedInput}); can be called regardless of what {@link #needMoreInput}
26+
* (with <code>feedInput</code> in sub-class); can be called regardless of what {@link #needMoreInput}
4427
* returns. After calling this method, no more data can be fed; and parser assumes
4528
* no more data will be available.
4629
*/

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParser.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
* extending it with features needed to process data in non-blocking
1111
* ("asynchronous")
1212
*/
13-
public interface NonBlockingParser
14-
extends NonBlockingInputFeeder
13+
public interface NonBlockingParser<F extends NonBlockingInputFeeder>
1514
{
15+
/**
16+
* Accessor for getting handle to the input feeder to use for this parser
17+
*/
18+
public F getInputFeeder();
19+
1620
/**
1721
* Method that can be called when current token is not yet
1822
* available via {@link com.fasterxml.jackson.core.JsonParser#currentToken},

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParserImpl.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
public class NonBlockingParserImpl
1818
extends ParserBase
19-
implements NonBlockingParser, NonBlockingInputFeeder
19+
implements NonBlockingParser<NonBlockingByteArrayFeeder>,
20+
NonBlockingByteArrayFeeder
2021
{
2122
private final static byte[] NO_BYTES = new byte[0];
2223
private final static int[] NO_INTS = new int[0];
@@ -36,7 +37,6 @@ public class NonBlockingParserImpl
3637
*/
3738
protected final static int STATE_INITIAL = 0;
3839

39-
4040
/**
4141
* State for recognized header marker, either in-feed or initial.
4242
*/
@@ -298,7 +298,7 @@ protected boolean handleSignature(boolean consumeFirstByte, boolean throwExcepti
298298
}
299299
return false;
300300
}
301-
// Good enough; just need version info from 4th byte...
301+
// Good enough; just need version info from 4th byte...
302302
if (++_inputPtr >= _inputEnd) {
303303
_loadMoreGuaranteed();
304304
}
@@ -461,9 +461,8 @@ protected void _releaseBuffers() throws IOException
461461
String[] nameBuf = _seenNames;
462462
if (nameBuf != null && nameBuf.length > 0) {
463463
_seenNames = null;
464-
/* 28-Jun-2011, tatu: With 1.9, caller needs to clear the buffer;
465-
* but we only need to clear up to count as it is not a hash area
466-
*/
464+
// Need to clear the buffer;
465+
// but we only need to clear up to count as it is not a hash area
467466
if (_seenNameCount > 0) {
468467
Arrays.fill(nameBuf, 0, _seenNameCount, null);
469468
}
@@ -474,9 +473,8 @@ protected void _releaseBuffers() throws IOException
474473
String[] valueBuf = _seenStringValues;
475474
if (valueBuf != null && valueBuf.length > 0) {
476475
_seenStringValues = null;
477-
/* 28-Jun-2011, tatu: With 1.9, caller needs to clear the buffer;
478-
* but we only need to clear up to count as it is not a hash area
479-
*/
476+
// Need to clear the buffer;
477+
// but we only need to clear up to count as it is not a hash area
480478
if (_seenStringValueCount > 0) {
481479
Arrays.fill(valueBuf, 0, _seenStringValueCount, null);
482480
}
@@ -703,10 +701,10 @@ public String getCurrentName() throws IOException
703701
public NumberType getNumberType()
704702
throws IOException
705703
{
706-
if (_got32BitFloat) {
707-
return NumberType.FLOAT;
708-
}
709-
return super.getNumberType();
704+
if (_got32BitFloat) {
705+
return NumberType.FLOAT;
706+
}
707+
return super.getNumberType();
710708
}
711709

712710
/*
@@ -754,6 +752,11 @@ public void endOfInput() {
754752
/**********************************************************************
755753
*/
756754

755+
@Override
756+
public NonBlockingByteArrayFeeder getInputFeeder() {
757+
return this;
758+
}
759+
757760
@Override
758761
public JsonToken peekNextToken() throws IOException
759762
{

0 commit comments

Comments
 (0)