mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Merge pull request #139 from owncloud/available_offline_folder
Close streams in GetRemoteUserAvatarOperation
This commit is contained in:
		
						commit
						fd9067ef4a
					
				| @ -28,6 +28,7 @@ package com.owncloud.android.lib.resources.users; | |||||||
| 
 | 
 | ||||||
| import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||||
| import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||||
|  | import java.io.IOException; | ||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| 
 | 
 | ||||||
| @ -73,6 +74,8 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | |||||||
|         RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
|         GetMethod get = null; |         GetMethod get = null; | ||||||
|         InputStream inputStream = null; |         InputStream inputStream = null; | ||||||
|  |         BufferedInputStream bis = null; | ||||||
|  |         ByteArrayOutputStream bos = null; | ||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             String uri = |             String uri = | ||||||
| @ -81,9 +84,19 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | |||||||
|             ; |             ; | ||||||
|             Log_OC.d(TAG, "avatar URI: " + uri); |             Log_OC.d(TAG, "avatar URI: " + uri); | ||||||
|             get = new GetMethod(uri); |             get = new GetMethod(uri); | ||||||
|  |             /*  Conditioned call is corrupting the input stream of the connection. | ||||||
|  |                 Seems that response with 304 is also including the avatar in the response body, | ||||||
|  |                 though it's forbidden by HTTPS specification. Besides, HTTPClient library | ||||||
|  |                 assumes there is nothing in the response body, but the bytes are read | ||||||
|  |                 by the next request, resulting in an exception due to a corrupt status line | ||||||
|  | 
 | ||||||
|  |                 Maybe when we have a real API we can enable this again. | ||||||
|  | 
 | ||||||
|             if (mCurrentEtag != null && mCurrentEtag.length() > 0) { |             if (mCurrentEtag != null && mCurrentEtag.length() > 0) { | ||||||
|                 get.addRequestHeader(IF_NONE_MATCH_HEADER, "\"" + mCurrentEtag + "\""); |                 get.addRequestHeader(IF_NONE_MATCH_HEADER, "\"" + mCurrentEtag + "\""); | ||||||
|             } |             } | ||||||
|  |             */ | ||||||
|  | 
 | ||||||
|             //get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); |             //get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||||
|             int status = client.executeMethod(get); |             int status = client.executeMethod(get); | ||||||
|             if (isSuccess(status)) { |             if (isSuccess(status)) { | ||||||
| @ -111,8 +124,8 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
|                 /// download will be performed to a buffer |                 /// download will be performed to a buffer | ||||||
|                 inputStream = get.getResponseBodyAsStream(); |                 inputStream = get.getResponseBodyAsStream(); | ||||||
|                 BufferedInputStream bis = new BufferedInputStream(inputStream); |                 bis = new BufferedInputStream(inputStream); | ||||||
|                 ByteArrayOutputStream bos = new ByteArrayOutputStream(totalToTransfer); |                 bos = new ByteArrayOutputStream(totalToTransfer); | ||||||
| 
 | 
 | ||||||
|                 long transferred = 0; |                 long transferred = 0; | ||||||
|                 byte[] bytes = new byte[4096]; |                 byte[] bytes = new byte[4096]; | ||||||
| @ -147,8 +160,24 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             if (get != null) { |             if (get != null) { | ||||||
|  |                 try { | ||||||
|                     if (inputStream != null) { |                     if (inputStream != null) { | ||||||
|                         client.exhaustResponse(inputStream); |                         client.exhaustResponse(inputStream); | ||||||
|  |                         if (bis != null) { | ||||||
|  |                             bis.close(); | ||||||
|  |                         } else { | ||||||
|  |                             inputStream.close(); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } catch (IOException i) { | ||||||
|  |                     Log_OC.e(TAG, "Unexpected exception closing input stream ", i); | ||||||
|  |                 } | ||||||
|  |                 try { | ||||||
|  |                     if (bos != null) { | ||||||
|  |                         bos.close(); | ||||||
|  |                     } | ||||||
|  |                 } catch (IOException o) { | ||||||
|  |                     Log_OC.e(TAG, "Unexpected exception closing output stream ", o); | ||||||
|                 } |                 } | ||||||
|                 get.releaseConnection(); |                 get.releaseConnection(); | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -68,7 +68,11 @@ public class GetUserAvatarTest extends RemoteTest { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Test get user avatar only if changed, but wasn't changed |      * Test get user avatar only if changed, but wasn't changed | ||||||
|  |      * | ||||||
|  |      * DISABLED: conditioned call has been disabled due to problems with the network stack; | ||||||
|  |      * see comment in src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java#87 | ||||||
|      */ |      */ | ||||||
|  |     /* | ||||||
|     public void testGetUserAvatarOnlyIfChangedAfterUnchanged() { |     public void testGetUserAvatarOnlyIfChangedAfterUnchanged() { | ||||||
|         RemoteOperationResult result = mActivity.getUserAvatar(AVATAR_DIMENSION, null); |         RemoteOperationResult result = mActivity.getUserAvatar(AVATAR_DIMENSION, null); | ||||||
|         ResultData userAvatar = (ResultData) result.getData().get(0); |         ResultData userAvatar = (ResultData) result.getData().get(0); | ||||||
| @ -79,6 +83,7 @@ public class GetUserAvatarTest extends RemoteTest { | |||||||
|         assertFalse(result.isSuccess()); |         assertFalse(result.isSuccess()); | ||||||
|         assertTrue(result.getHttpCode() == HttpStatus.SC_NOT_MODIFIED); |         assertTrue(result.getHttpCode() == HttpStatus.SC_NOT_MODIFIED); | ||||||
|     } |     } | ||||||
|  |     */ | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Test get user avatar only if changed, and was changed |      * Test get user avatar only if changed, and was changed | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user