/**
* Implementation of {@link #testGetAsDataInputFromURL()} and {@link #testGetAsDataInputFromStream()}.
*/
private void testGetAsDataInput(final boolean asStream) throws DataStoreException, IOException {
final StorageConnector connection = create(asStream);
final DataInput input = connection.getStorageAs(DataInput.class);
assertSame("Value shall be cached.", input, connection.getStorageAs(DataInput.class));
assertInstanceOf("Needs the SIS implementation", ChannelImageInputStream.class, input);
assertSame("Instance shall be shared.", input, connection.getStorageAs(ChannelDataInput.class));
/*
* Reads a single integer for checking that the stream is at the right position, then close the stream.
* Since the file is a compiled Java class, the integer that we read shall be the Java magic number.
*/
final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
assertTrue("channel.isOpen()", channel.isOpen());
assertEquals(MAGIC_NUMBER, input.readInt());
connection.closeAllExcept(null);
assertFalse("channel.isOpen()", channel.isOpen());
}