@ -74,13 +74,13 @@ class ObjectUploadListener implements ReadListener {
private final HttpServletResponse response ;
private final HttpServletResponse response ;
private FileLfsRepository repository ;
private final ServletInputStream in ;
private final ServletInputStream in ;
private final ReadableByteChannel inChannel ;
private final ReadableByteChannel inChannel ;
private WritableByteChannel out ;
private final AtomicObjectOutputStream out ;
private WritableByteChannel channel ;
private final ByteBuffer buffer = ByteBuffer . allocateDirect ( 8192 ) ;
private final ByteBuffer buffer = ByteBuffer . allocateDirect ( 8192 ) ;
@ -98,12 +98,12 @@ class ObjectUploadListener implements ReadListener {
AsyncContext context , HttpServletRequest request ,
AsyncContext context , HttpServletRequest request ,
HttpServletResponse response , AnyLongObjectId id )
HttpServletResponse response , AnyLongObjectId id )
throws FileNotFoundException , IOException {
throws FileNotFoundException , IOException {
this . repository = repository ;
this . context = context ;
this . context = context ;
this . response = response ;
this . response = response ;
this . in = request . getInputStream ( ) ;
this . in = request . getInputStream ( ) ;
this . inChannel = Channels . newChannel ( in ) ;
this . inChannel = Channels . newChannel ( in ) ;
this . out = repository . getWriteChannel ( id ) ;
this . out = repository . getOutputStream ( id ) ;
this . channel = Channels . newChannel ( out ) ;
response . setContentType ( Constants . CONTENT_TYPE_GIT_LFS_JSON ) ;
response . setContentType ( Constants . CONTENT_TYPE_GIT_LFS_JSON ) ;
}
}
@ -117,12 +117,12 @@ class ObjectUploadListener implements ReadListener {
while ( in . isReady ( ) ) {
while ( in . isReady ( ) ) {
if ( inChannel . read ( buffer ) > 0 ) {
if ( inChannel . read ( buffer ) > 0 ) {
buffer . flip ( ) ;
buffer . flip ( ) ;
out . write ( buffer ) ;
channel . write ( buffer ) ;
buffer . compact ( ) ;
buffer . compact ( ) ;
} else {
} else {
buffer . flip ( ) ;
buffer . flip ( ) ;
while ( buffer . hasRemaining ( ) ) {
while ( buffer . hasRemaining ( ) ) {
out . write ( buffer ) ;
channel . write ( buffer ) ;
}
}
close ( ) ;
close ( ) ;
return ;
return ;
@ -141,7 +141,7 @@ class ObjectUploadListener implements ReadListener {
protected void close ( ) throws IOException {
protected void close ( ) throws IOException {
try {
try {
inChannel . close ( ) ;
inChannel . close ( ) ;
out . close ( ) ;
channel . close ( ) ;
// TODO check if status 200 is ok for PUT request, HTTP foresees 204
// TODO check if status 200 is ok for PUT request, HTTP foresees 204
// for successful PUT without response body
// for successful PUT without response body
response . setStatus ( HttpServletResponse . SC_OK ) ;
response . setStatus ( HttpServletResponse . SC_OK ) ;
@ -157,9 +157,9 @@ class ObjectUploadListener implements ReadListener {
@Override
@Override
public void onError ( Throwable e ) {
public void onError ( Throwable e ) {
try {
try {
repository . abortWrite ( ) ;
out . abort ( ) ;
inChannel . close ( ) ;
inChannel . close ( ) ;
out . close ( ) ;
channel . close ( ) ;
int status ;
int status ;
if ( e instanceof CorruptLongObjectException ) {
if ( e instanceof CorruptLongObjectException ) {
status = HttpStatus . SC_BAD_REQUEST ;
status = HttpStatus . SC_BAD_REQUEST ;