def total = 0;
def len = 0;
def buffer = new byte[131072];
def InputStream is = conn.getInputStream();
while ( ( len = is.read(buffer) ) != -1 ) {
output.write( buffer, 0, len );
total += len;
}
output.flush();
println "Downloaded total: ${total} bytes successfully.";
What is the syntax for creating a byte array in Groovy?
I thought it was originally ``def data = new byte[8192]’’, but the Groovy compiler does not like it at all.
Does Groovy even support the ``byte’’ type? If not, then the bytes are converted implicitly to “ints” then what I am trying to do in Groovy will not work.
From 5000ft, I am attempting to download data using Groovy into a file using an efficient buffer.
--
Peter Pilgrim | E-Channel Services, Technical Lead, eBusiness
Lloyds Banking Group | Wholesale Markets & Treasury IT
33 Old Broad Street, London, EC2N 1HZ, UK
' +44 (0)207 158 6135 | ( +44 (0)1234 567 8901
Don’t bother.
Solved with
Output << input
If you want to monitor actually how many bytes were copied from stream to stream descend into Java and supply some data object to fill and return.
--
Peter Pilgrim | E-Channel Services, Technical Lead, eBusiness
Lloyds Banking Group | Wholesale Markets & Treasury IT
33 Old Broad Street, London, EC2N 1HZ, UK
' +44 (0)207 158 6135 | ( +44 (0)1234 567 8901