Skip to content

Commit 0fda8eb

Browse files
committed
Test Largefile download
1 parent 1eb3d70 commit 0fda8eb

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

bindings/jaxrs/src/main/java/org/commonjava/indy/core/bind/jaxrs/util/TransferStreamingOutput.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void write( final OutputStream out )
6161
throws IOException, WebApplicationException
6262
{
6363
long start = System.nanoTime();
64-
try
64+
/*try
6565
{
6666
CountingOutputStream cout = new CountingOutputStream( out );
6767
IOUtils.copy( stream, cout );
@@ -81,6 +81,36 @@ public void write( final OutputStream out )
8181
finally
8282
{
8383
IOUtils.closeQuietly( stream );
84+
}*/
85+
86+
byte[] buffer = new byte[8192]; // 8KB buffer
87+
int bytesRead;
88+
89+
try
90+
{
91+
CountingOutputStream cout = new CountingOutputStream( out );
92+
93+
while ((bytesRead = stream.read(buffer)) != -1)
94+
{
95+
cout.write(buffer, 0, bytesRead);
96+
cout.flush();
97+
}
98+
99+
Logger logger = LoggerFactory.getLogger( getClass() );
100+
logger.trace( "Wrote: {} bytes", cout.getByteCount() );
101+
102+
String name = getName( metricsConfig.getNodePrefix(), TRANSFER_METRIC_NAME,
103+
getDefaultName( TransferStreamingOutput.class, "write" ), METER );
104+
105+
long end = System.nanoTime();
106+
double elapsed = (end-start)/NANOS_PER_SEC;
107+
108+
Meter meter = metricsManager.getMeter( name );
109+
meter.mark( Math.round( cout.getByteCount() / elapsed ) );
110+
}
111+
finally
112+
{
113+
IOUtils.closeQuietly(stream); // Ensure the InputStream is closed properly
84114
}
85115
}
86116

0 commit comments

Comments
 (0)