Skip to content

Commit

Permalink
upgrade to gradle v6.2.2 and use strict google java style (minio#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana authored Mar 14, 2020
1 parent 24d788d commit e0f72e9
Show file tree
Hide file tree
Showing 166 changed files with 6,659 additions and 6,887 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
- name: Gradle build on ${{ matrix.java-version }}
if: matrix.os == 'ubuntu-latest'
run: |
./gradlew check
./gradlew build
./gradlew runFunctionalTest
- name: Gradle build on ${{ matrix.java-version }}
if: matrix.os == 'windows-latest'
run: |
$Env:Path += ';.'
gradlew.bat build
gradlew.bat runFunctionalTest
13 changes: 4 additions & 9 deletions api/src/main/java/io/minio/AwsS3Endpoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
import java.util.HashMap;
import java.util.Map;


/**
* Amazon AWS S3 endpoints for various regions.
*/
/** Amazon AWS S3 endpoints for various regions. */
enum AwsS3Endpoints {
INSTANCE;
private final Map<String, String> endpoints = new HashMap<>();
Expand All @@ -32,7 +29,7 @@ enum AwsS3Endpoints {
endpoints.put("ap-northeast-1", "s3-ap-northeast-1.amazonaws.com");
// ap-northeast-2
endpoints.put("ap-northeast-2", "s3-ap-northeast-2.amazonaws.com");
//ap-south-1
// ap-south-1
endpoints.put("ap-south-1", "s3-ap-south-1.amazonaws.com");
// ap-southeast-1
endpoints.put("ap-southeast-1", "s3-ap-southeast-1.amazonaws.com");
Expand All @@ -54,17 +51,15 @@ enum AwsS3Endpoints {
endpoints.put("us-east-1", "s3.amazonaws.com");
// us-east-2
endpoints.put("us-east-2", "s3-us-east-2.amazonaws.com");
//ca-central-1
// ca-central-1
endpoints.put("ca-central-1", "s3.ca-central-1.amazonaws.com");
// cn-north-1
endpoints.put("cn-north-1", "s3.cn-north-1.amazonaws.com.cn");
// cn-northwest-1
endpoints.put("cn-northwest-1", "s3.cn-northwest-1.amazonaws.com.cn");
}

/**
* Gets Amazon S3 endpoint for the relevant region.
*/
/** Gets Amazon S3 endpoint for the relevant region. */
public String endpoint(String region) {
String s = AwsS3Endpoints.INSTANCE.endpoints.get(region);
if (s == null) {
Expand Down
1 change: 0 additions & 1 deletion api/src/main/java/io/minio/BucketEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ public interface BucketEventListener {

void updateEvent(NotificationInfo info);
}

24 changes: 5 additions & 19 deletions api/src/main/java/io/minio/BucketRegionCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
* A singleton bucket/region cache map.
*/
/** A singleton bucket/region cache map. */
enum BucketRegionCache {
INSTANCE;
private final Map<String, String> regionMap = new ConcurrentHashMap<>();

/**
* Returns AWS region for given bucket name.
*/
/** Returns AWS region for given bucket name. */
public String region(String bucketName) {
if (bucketName == null) {
return "us-east-1";
Expand All @@ -43,28 +38,19 @@ public String region(String bucketName) {
}
}


/**
* Sets bucket name and its region to BucketRegionCache.
*/
/** Sets bucket name and its region to BucketRegionCache. */
public void set(String bucketName, String region) {
this.regionMap.put(bucketName, region);
}


/**
* Removes region cache of the bucket if any.
*/
/** Removes region cache of the bucket if any. */
public void remove(String bucketName) {
if (bucketName != null) {
this.regionMap.remove(bucketName);
}
}


/**
* Returns true if given bucket name is in the map else false.
*/
/** Returns true if given bucket name is in the map else false. */
public boolean exists(String bucketName) {
return this.regionMap.get(bucketName) != null;
}
Expand Down
56 changes: 28 additions & 28 deletions api/src/main/java/io/minio/ChunkedInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@

package io.minio;

import io.minio.errors.InternalException;
import io.minio.errors.InsufficientDataException;

import io.minio.errors.InternalException;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.ZonedDateTime;


class ChunkedInputStream extends InputStream {
// Chunk size in chunked upload for PUT object is 64KiB
private static final int CHUNK_SIZE = 64 * 1024;
Expand All @@ -38,7 +36,8 @@ class ChunkedInputStream extends InputStream {
// 10000;chunk-signature=ad80c730a21e5b8d04586a2213dd63b9a0e99e0e2307b0ade35a65485a288648\r\n<65536-bytes>\r\n
// From the above value, a full chunk size 65626 is by
// len(hex string of 64KiB) = 5 (+)
// len(;chunk-signature=ad80c730a21e5b8d04586a2213dd63b9a0e99e0e2307b0ade35a65485a288648\r\n) = 83 (+)
// len(;chunk-signature=ad80c730a21e5b8d04586a2213dd63b9a0e99e0e2307b0ade35a65485a288648\r\n) = 83
// (+)
// <65536 bytes> = 65536 (+)
// len(\r\n) = 2
private static final int FULL_CHUNK_LEN = 65626;
Expand Down Expand Up @@ -67,12 +66,15 @@ class ChunkedInputStream extends InputStream {
// Counter denotes how many bytes the consumer read from this stream.
private int bytesRead = 0;


/**
* Create new ChunkedInputStream for given input stream.
*/
public ChunkedInputStream(InputStream inputStream, int streamSize, ZonedDateTime date, String region,
String secretKey, String seedSignature) throws IOException {
/** Create new ChunkedInputStream for given input stream. */
public ChunkedInputStream(
InputStream inputStream,
int streamSize,
ZonedDateTime date,
String region,
String secretKey,
String seedSignature)
throws IOException {
this.inputStream = inputStream;
this.streamSize = streamSize;
this.date = date;
Expand All @@ -92,7 +94,6 @@ public ChunkedInputStream(InputStream inputStream, int streamSize, ZonedDateTime
this.length += FINAL_ADDITIONAL_CHUNK_LEN;
}


private int readData(byte[] buf) throws IOException {
if (this.isEof) {
return -1;
Expand All @@ -117,12 +118,13 @@ private int readData(byte[] buf) throws IOException {
return totalBytesRead;
}


private void createChunkBody(byte[] chunk)
throws IOException, NoSuchAlgorithmException, InvalidKeyException, InsufficientDataException, InternalException {
throws IOException, NoSuchAlgorithmException, InvalidKeyException, InsufficientDataException,
InternalException {
String chunkSha256 = Digest.sha256Hash(chunk, chunk.length);
String signature = Signer.getChunkSignature(chunkSha256, this.date, this.region, this.secretKey,
this.prevSignature);
String signature =
Signer.getChunkSignature(
chunkSha256, this.date, this.region, this.secretKey, this.prevSignature);

ByteArrayOutputStream os = new ByteArrayOutputStream();
// Add metadata.
Expand All @@ -139,27 +141,25 @@ private void createChunkBody(byte[] chunk)
this.prevSignature = signature;
}


private int readChunk(int chunkSize)
throws IOException, NoSuchAlgorithmException, InvalidKeyException, InsufficientDataException, InternalException {
throws IOException, NoSuchAlgorithmException, InvalidKeyException, InsufficientDataException,
InternalException {
byte[] chunk = new byte[chunkSize];
int len = readData(chunk);
if (len < 0) {
return -1;
}

if (len != chunkSize) {
throw new InsufficientDataException("Insufficient data. read = " + len + " expected = " + chunkSize);
throw new InsufficientDataException(
"Insufficient data. read = " + len + " expected = " + chunkSize);
}

createChunkBody(chunk);
return this.chunkBody.length;
}


/**
* read single byte from chunk body.
*/
/** read single byte from chunk body. */
public int read() throws IOException {
if (this.bytesRead == this.length) {
// All chunks and final additional chunk are read.
Expand Down Expand Up @@ -196,15 +196,15 @@ public int read() throws IOException {
int value = this.chunkBody[this.chunkPos] & 0xFF;
this.chunkPos++;
return value;
} catch (NoSuchAlgorithmException | InvalidKeyException | InsufficientDataException | InternalException e) {
} catch (NoSuchAlgorithmException
| InvalidKeyException
| InsufficientDataException
| InternalException e) {
throw new IOException(e.getCause());
}
}


/**
* return length of data ChunkedInputStream supposes to produce.
*/
/** return length of data ChunkedInputStream supposes to produce. */
public int length() {
return this.length;
}
Expand Down
4 changes: 1 addition & 3 deletions api/src/main/java/io/minio/CloseableIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
import java.io.Closeable;
import java.util.Iterator;

public interface CloseableIterator<T> extends Iterator<T>, Closeable {
}

public interface CloseableIterator<T> extends Iterator<T>, Closeable {}
89 changes: 56 additions & 33 deletions api/src/main/java/io/minio/ComposeSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.Map;
import java.util.TreeMap;
import io.minio.CopyConditions;

public class ComposeSource {
private String bucketName;
Expand All @@ -32,45 +31,54 @@ public class ComposeSource {
private long objectSize;
private Map<String, String> headers;

/**
* Create new ComposeSource for given bucket and object.
*/
/** Create new ComposeSource for given bucket and object. */
public ComposeSource(String bucketName, String objectName) throws IllegalArgumentException {
this(bucketName, objectName, null, null, null, null, null);
}

/**
* Create new ComposeSource for given bucket, object, offset and length.
*/
/** Create new ComposeSource for given bucket, object, offset and length. */
public ComposeSource(String bucketName, String objectName, Long offset, Long length)
throws IllegalArgumentException {
throws IllegalArgumentException {
this(bucketName, objectName, offset, length, null, null, null);
}

/**
* Create new ComposeSource for given bucket, object, offset, length and headerMap.
*/
public ComposeSource(String bucketName, String objectName, Long offset, Long length,
Map<String, String> headerMap) throws IllegalArgumentException {
/** Create new ComposeSource for given bucket, object, offset, length and headerMap. */
public ComposeSource(
String bucketName, String objectName, Long offset, Long length, Map<String, String> headerMap)
throws IllegalArgumentException {
this(bucketName, objectName, offset, length, headerMap, null, null);
}

/**
* Create new ComposeSource for given bucket, object, offset, length, headerMap and CopyConditions.
* Create new ComposeSource for given bucket, object, offset, length, headerMap and
* CopyConditions.
*/
public ComposeSource(String bucketName, String objectName, Long offset, Long length,
Map<String, String> headerMap, CopyConditions copyConditions) throws IllegalArgumentException {
public ComposeSource(
String bucketName,
String objectName,
Long offset,
Long length,
Map<String, String> headerMap,
CopyConditions copyConditions)
throws IllegalArgumentException {
this(bucketName, objectName, offset, length, headerMap, copyConditions, null);
}

/**
* Creates new ComposeSource for given bucket, object, offset, length, headerMap, CopyConditions
* and server side encryption.
*
* @throws IllegalArgumentException upon invalid value is passed to a method.
* @throws IllegalArgumentException upon invalid value is passed to a method.
*/
public ComposeSource(String bucketName, String objectName, Long offset, Long length, Map<String, String> headerMap,
CopyConditions copyConditions, ServerSideEncryption sse) throws IllegalArgumentException {
public ComposeSource(
String bucketName,
String objectName,
Long offset,
Long length,
Map<String, String> headerMap,
CopyConditions copyConditions,
ServerSideEncryption sse)
throws IllegalArgumentException {
if (bucketName == null) {
throw new IllegalArgumentException("Source bucket name cannot be empty");
}
Expand Down Expand Up @@ -100,25 +108,43 @@ public ComposeSource(String bucketName, String objectName, Long offset, Long len
this.sse = sse;
}

/**
* Constructs header .
*
*/
/** Constructs header . */
public void buildHeaders(long objectSize, String etag) throws IllegalArgumentException {
if (offset != null && offset >= objectSize) {
throw new IllegalArgumentException("source " + bucketName + "/" + objectName + ": offset " + offset
+ " is beyond object size " + objectSize);
throw new IllegalArgumentException(
"source "
+ bucketName
+ "/"
+ objectName
+ ": offset "
+ offset
+ " is beyond object size "
+ objectSize);
}

if (length != null) {
if (length > objectSize) {
throw new IllegalArgumentException("source " + bucketName + "/" + objectName + ": length " + length
+ " is beyond object size " + objectSize);
throw new IllegalArgumentException(
"source "
+ bucketName
+ "/"
+ objectName
+ ": length "
+ length
+ " is beyond object size "
+ objectSize);
}

if (offset + length > objectSize) {
throw new IllegalArgumentException("source " + bucketName + "/" + objectName + ": compose size "
+ (offset + length) + " is beyond object size " + objectSize);
throw new IllegalArgumentException(
"source "
+ bucketName
+ "/"
+ objectName
+ ": compose size "
+ (offset + length)
+ " is beyond object size "
+ objectSize);
}
}

Expand Down Expand Up @@ -166,10 +192,7 @@ public ServerSideEncryption sse() {
return sse;
}

/**
* Returns header.
*
*/
/** Returns header. */
public Map<String, String> headers() {
Map<String, String> headers = null;

Expand Down
Loading

0 comments on commit e0f72e9

Please sign in to comment.