Skip to content

Commit 4e33803

Browse files
author
Zhen
committed
Fix after review
1 parent ce414d3 commit 4e33803

File tree

8 files changed

+14
-41
lines changed

8 files changed

+14
-41
lines changed

driver/src/main/java/org/neo4j/driver/internal/net/SocketClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void updateProtocol( String serverVersion )
143143
{
144144
if( version( serverVersion ).lessThan( v3_2_0 ) )
145145
{
146-
setProtocol( SocketProtocolV1.create( channel, false ) );
146+
setProtocol( SocketProtocolV1.createWithoutByteArraySupport( channel ) );
147147
}
148148
}
149149

driver/src/main/java/org/neo4j/driver/internal/net/SocketProtocolV1.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ public class SocketProtocolV1 implements SocketProtocol
3434
public static SocketProtocol create( ByteChannel channel )
3535
{
3636
/*by default the byte array support is enabled*/
37-
return create( channel, true );
37+
return new SocketProtocolV1( channel, true );
3838
}
3939

40-
public static SocketProtocol create( ByteChannel channel, boolean byteArraySupportEnabled )
40+
public static SocketProtocol createWithoutByteArraySupport( ByteChannel channel )
4141
{
42-
return new SocketProtocolV1( channel, byteArraySupportEnabled );
42+
return new SocketProtocolV1( channel, false );
4343
}
4444

45-
public SocketProtocolV1( ByteChannel channel, boolean byteArraySupportEnabled )
45+
private SocketProtocolV1( ByteChannel channel, boolean byteArraySupportEnabled )
4646
{
4747
messageFormat = new PackStreamMessageFormatV1();
4848
this.writer = messageFormat.newWriter( channel, byteArraySupportEnabled );

driver/src/main/java/org/neo4j/driver/internal/packstream/PackStream.java

-24
Original file line numberDiff line numberDiff line change
@@ -535,30 +535,6 @@ public String unpackString() throws IOException
535535
return new String(unpackUtf8(markerByte), UTF_8);
536536
}
537537

538-
public byte[] unpackRawBytes() throws IOException
539-
{
540-
final byte markerByte = in.readByte();
541-
542-
switch(markerByte)
543-
{
544-
case BYTES_8: return unpackRawBytes( unpackUINT8() );
545-
case BYTES_16: return unpackRawBytes( unpackUINT16() );
546-
case BYTES_32:
547-
{
548-
long size = unpackUINT32();
549-
if ( size <= Integer.MAX_VALUE )
550-
{
551-
return unpackRawBytes( (int) size );
552-
}
553-
else
554-
{
555-
throw new Overflow( "BYTES_32 too long for Java" );
556-
}
557-
}
558-
default: throw new Unexpected( "Expected binary data, but got: 0x" + toHexString( markerByte & 0xFF ));
559-
}
560-
}
561-
562538
/**
563539
* This may seem confusing. This method exists to move forward the internal pointer when encountering
564540
* a null value. The idiomatic usage would be someone using {@link #peekNextType()} to detect a null type,

driver/src/main/java/org/neo4j/driver/internal/util/ServerVersion.java

-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ public static ServerVersion version( Driver driver )
5454
}
5555
}
5656

57-
public static ServerVersion version( Session session )
58-
{
59-
String versionString = session.run( "RETURN 1" ).consume().server().version();
60-
return version( versionString );
61-
}
62-
6357
public static ServerVersion version( String server )
6458
{
6559
if ( server == null )

driver/src/main/java/org/neo4j/driver/v1/Values.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static Value value( Object value )
8585
if ( value instanceof Iterable<?> ) { return value( (Iterable<Object>) value ); }
8686
if ( value instanceof Iterator<?> ) { return value( (Iterator<Object>) value ); }
8787

88-
if ( value instanceof byte[] ) { return new BytesValue( (byte[]) value ); }
88+
if ( value instanceof byte[] ) { return value( (byte[]) value ); }
8989
if ( value instanceof boolean[] ) { return value( (boolean[]) value ); }
9090
if ( value instanceof String[] ) { return value( (String[]) value ); }
9191
if ( value instanceof long[] ) { return value( (long[]) value ); }
@@ -98,6 +98,7 @@ public static Value value( Object value )
9898
throw new ClientException( "Unable to convert " + value.getClass().getName() + " to Neo4j Value." );
9999
}
100100

101+
101102
public static Value[] values( final Object... input )
102103
{
103104
Value[] values = new Value[input.length];
@@ -116,7 +117,7 @@ public static Value value( Value... input )
116117
return new ListValue( values );
117118
}
118119

119-
private static Value bytesValue( byte[] input )
120+
public static BytesValue value( byte... input )
120121
{
121122
return new BytesValue( input );
122123
}

driver/src/test/java/org/neo4j/driver/internal/packstream/BufferedChannelOutput.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public PackOutput writeDouble( double value ) throws IOException
107107
return this;
108108
}
109109

110-
private void ensure(int size ) throws IOException
110+
private void ensure( int size ) throws IOException
111111
{
112112
if ( buffer.remaining() < size )
113113
{

driver/src/test/java/org/neo4j/driver/internal/packstream/PackStreamTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public void testCanPackAndUnpackByteArrays() throws Throwable
344344

345345
// Then
346346
assertThat( packType, equalTo( PackType.BYTES ) );
347-
assertArrayEquals( array, unpacker.unpackRawBytes() );
347+
assertArrayEquals( array, unpacker.unpackBytes() );
348348
}
349349
}
350350

@@ -391,7 +391,7 @@ public void testCanPackAndUnpackBytes() throws Throwable
391391

392392
// Then
393393
assertThat( packType, equalTo( PackType.BYTES ) );
394-
assertArrayEquals( "ABCDEFGHIJ".getBytes(), unpacker.unpackRawBytes() );
394+
assertArrayEquals( "ABCDEFGHIJ".getBytes(), unpacker.unpackBytes() );
395395

396396
}
397397

driver/src/test/java/org/neo4j/driver/v1/integration/ParametersIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import static org.junit.Assert.fail;
4141
import static org.junit.Assume.assumeFalse;
4242
import static org.junit.Assume.assumeTrue;
43+
import static org.neo4j.driver.internal.util.ServerVersion.version;
4344
import static org.neo4j.driver.v1.Values.ofValue;
4445
import static org.neo4j.driver.v1.Values.parameters;
4546

@@ -151,7 +152,8 @@ public void shouldBeAbleToSetAndReturnDoubleProperty()
151152

152153
private boolean supportsBytes()
153154
{
154-
return ServerVersion.version( session ).greaterThanOrEqual( ServerVersion.v3_2_0 );
155+
String versionString = session.run( "RETURN 1" ).consume().server().version();
156+
return version( versionString ).greaterThanOrEqual( ServerVersion.v3_2_0 );
155157
}
156158

157159
@Test

0 commit comments

Comments
 (0)