@ -28,7 +28,7 @@ import com.fr.workspace.resource.ResourceIOException;
import java.io.ByteArrayInputStream ;
import java.io.ByteArrayInputStream ;
import java.io.InputStream ;
import java.io.InputStream ;
import java.net.URL ;
import java.net.URL ;
import java.net.URLConnection ;
import java.nio.charset.Charset ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.List ;
@ -40,6 +40,7 @@ import java.util.List;
public class S3ResourceRepository extends BaseResourceRepository {
public class S3ResourceRepository extends BaseResourceRepository {
private static final String DELIMITER = "/" ;
private static final String DELIMITER = "/" ;
private static final String CHAR_SET = "UTF-8" ;
private final AmazonS3 s3 ;
private final AmazonS3 s3 ;
private final String bucket ;
private final String bucket ;
@ -162,18 +163,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override
@Override
public void write ( String path , byte [ ] data ) {
public void write ( String path , byte [ ] data ) {
ObjectMetadata metadata ;
s3 . putObject ( bucket , path , new String ( data , Charset . forName ( CHAR_SET ) ) ) ;
try {
metadata = s3 . getObjectMetadata ( bucket , path ) ;
} catch ( Exception e ) {
metadata = new ObjectMetadata ( ) ;
String mimeType = URLConnection . guessContentTypeFromName ( path ) ;
if ( mimeType ! = null ) {
metadata . setContentType ( mimeType ) ;
}
metadata . setContentLength ( data . length ) ;
}
s3 . putObject ( bucket , path , new ByteArrayInputStream ( data ) , metadata ) ;
}
}