Java tutorial
/* * Copyright 2012-2016 the Flamingo Community. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.exem.flamingo.web.filesystem.s3; import com.amazonaws.ClientConfiguration; import com.amazonaws.Protocol; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import java.io.IOException; import java.io.InputStream; class AwsS3Factory { /** * Classpath? <tt>aws.properties</tt> ?? . * <tt>aws.properties</tt> ?? <tt>accessKey</tt> <tt>secretKey</tt>? ?? . * * @return {@link AmazonS3} * @throws IOException Classpath? <tt>aws.properties</tt> ?? */ public static AmazonS3 createS3Client() throws IOException { InputStream is = AwsS3Factory.class.getResourceAsStream("/aws.properties"); return createS3Client(is); } /** * Properties? Input Stream? ? . * Properties? <tt>accessKey</tt> <tt>secretKey</tt>? ?? . * * @return {@link AmazonS3} * @throws IOException Properties ?? Input Stream? */ private static AmazonS3 createS3Client(InputStream is) throws IOException { AWSCredentials credentials = new PropertiesCredentials(is); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTP); return new AmazonS3Client(credentials, clientConfig); } }