Skip to content

Commit

Permalink
Fix readAllBytes with http files (#5202)
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso authored Aug 5, 2024
1 parent e7a879d commit 7e90ce6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ abstract class XFileSystemProvider extends FileSystemProvider {
int read(ByteBuffer buffer) throws IOException {
def data=0
int len=0
while( len<buffer.capacity() && (data=stream.read())!=-1 ) {
while( buffer.hasRemaining() && (data=stream.read())!=-1 ) {
buffer.put((byte)data)
len++
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class HttpFilesTests extends Specification {
then:
lines.size()>0
lines[0].startsWith('<!DOCTYPE html><html lang="en">')

}

def 'should check file properties' () {
Expand Down Expand Up @@ -190,27 +190,17 @@ class HttpFilesTests extends Specification {
@IgnoreIf({System.getenv('NXF_SMOKE')})
def 'should read lines' () {
given:
def path = Paths.get(new URI('ftp://ftp.ncbi.nlm.nih.gov/robots.txt'))

def uri = new URI('http://www.nextflow.io/index.html')
when:
def lines = Files.readAllLines(path, Charset.forName('UTF-8'))
def path = Paths.get(uri)
then:
lines[0] == 'User-agent: *'
lines[1] == 'Disallow: /'
}

@IgnoreIf({System.getenv('NXF_SMOKE')})
def 'should read all bytes' ( ) {
given:
def path = Paths.get(new URI('ftp://ftp.ncbi.nlm.nih.gov/robots.txt'))
path instanceof XPath

when:
def bytes = Files.readAllBytes(path)
def lines = new String(bytes).readLines()
def str = new String(Files.readAllBytes(path), Charset.forName('UTF-8'))
then:
lines[0] == 'User-agent: *'
lines[1] == 'Disallow: /'

str.size()>0
str.startsWith('<!DOCTYPE html><html lang="en">')
}

def 'should read with a newByteChannel' () {
Expand Down

0 comments on commit 7e90ce6

Please sign in to comment.