Example usage for java.util NoSuchElementException NoSuchElementException

List of usage examples for java.util NoSuchElementException NoSuchElementException

Introduction

In this page you can find the example usage for java.util NoSuchElementException NoSuchElementException.

Prototype

public NoSuchElementException() 

Source Link

Document

Constructs a NoSuchElementException with null as its error message string.

Usage

From source file:io.minio.MinioClient.java

/**
 * Returns {@code Iterable<Result<Upload>>} of given bucket name, prefix and recursive flag.
 * All parts size are aggregated when aggregatePartSize is true.
 *//*  w  w  w.  ja v  a  2 s  . c om*/
private Iterable<Result<Upload>> listIncompleteUploads(final String bucketName, final String prefix,
        final boolean recursive, final boolean aggregatePartSize) {
    return new Iterable<Result<Upload>>() {
        @Override
        public Iterator<Result<Upload>> iterator() {
            return new Iterator<Result<Upload>>() {
                private String nextKeyMarker;
                private String nextUploadIdMarker;
                private ListMultipartUploadsResult listMultipartUploadsResult;
                private Result<Upload> error;
                private Iterator<Upload> uploadIterator;
                private boolean completed = false;

                private synchronized void populate() {
                    String delimiter = "/";
                    if (recursive) {
                        delimiter = null;
                    }

                    this.listMultipartUploadsResult = null;
                    this.uploadIterator = null;

                    try {
                        this.listMultipartUploadsResult = listIncompleteUploads(bucketName, nextKeyMarker,
                                nextUploadIdMarker, prefix, delimiter, 1000);
                    } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException
                            | IOException | InvalidKeyException | NoResponseException | XmlPullParserException
                            | ErrorResponseException | InternalException e) {
                        this.error = new Result<>(null, e);
                    } finally {
                        if (this.listMultipartUploadsResult != null) {
                            this.uploadIterator = this.listMultipartUploadsResult.uploads().iterator();
                        } else {
                            this.uploadIterator = new LinkedList<Upload>().iterator();
                        }
                    }
                }

                private synchronized long getAggregatedPartSize(String objectName, String uploadId)
                        throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException,
                        IOException, InvalidKeyException, NoResponseException, XmlPullParserException,
                        ErrorResponseException, InternalException {
                    long aggregatedPartSize = 0;

                    for (Result<Part> result : listObjectParts(bucketName, objectName, uploadId)) {
                        aggregatedPartSize += result.get().partSize();
                    }

                    return aggregatedPartSize;
                }

                @Override
                public boolean hasNext() {
                    if (this.completed) {
                        return false;
                    }

                    if (this.error == null && this.uploadIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.uploadIterator.hasNext()
                            && this.listMultipartUploadsResult.isTruncated()) {
                        this.nextKeyMarker = this.listMultipartUploadsResult.nextKeyMarker();
                        this.nextUploadIdMarker = this.listMultipartUploadsResult.nextUploadIdMarker();
                        populate();
                    }

                    if (this.error != null) {
                        return true;
                    }

                    if (this.uploadIterator.hasNext()) {
                        return true;
                    }

                    this.completed = true;
                    return false;
                }

                @Override
                public Result<Upload> next() {
                    if (this.completed) {
                        throw new NoSuchElementException();
                    }

                    if (this.error == null && this.uploadIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.uploadIterator.hasNext()
                            && this.listMultipartUploadsResult.isTruncated()) {
                        this.nextKeyMarker = this.listMultipartUploadsResult.nextKeyMarker();
                        this.nextUploadIdMarker = this.listMultipartUploadsResult.nextUploadIdMarker();
                        populate();
                    }

                    if (this.error != null) {
                        this.completed = true;
                        return this.error;
                    }

                    if (this.uploadIterator.hasNext()) {
                        Upload upload = this.uploadIterator.next();

                        if (aggregatePartSize) {
                            long aggregatedPartSize;

                            try {
                                aggregatedPartSize = getAggregatedPartSize(upload.objectName(),
                                        upload.uploadId());
                            } catch (InvalidBucketNameException | NoSuchAlgorithmException
                                    | InsufficientDataException | IOException | InvalidKeyException
                                    | NoResponseException | XmlPullParserException | ErrorResponseException
                                    | InternalException e) {
                                // special case: ignore the error as we can't propagate the exception in next()
                                aggregatedPartSize = -1;
                            }

                            upload.setAggregatedPartSize(aggregatedPartSize);
                        }

                        return new Result<>(upload, null);
                    }

                    this.completed = true;
                    throw new NoSuchElementException();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:io.minio.MinioClient.java

/**
 * Executes List object parts of multipart upload for given bucket name, object name and upload ID and
 * returns {@code Iterable<Result<Part>>}.
 *///from  ww w .  j a v  a  2  s  . co  m
private Iterable<Result<Part>> listObjectParts(final String bucketName, final String objectName,
        final String uploadId) {
    return new Iterable<Result<Part>>() {
        @Override
        public Iterator<Result<Part>> iterator() {
            return new Iterator<Result<Part>>() {
                private int nextPartNumberMarker;
                private ListPartsResult listPartsResult;
                private Result<Part> error;
                private Iterator<Part> partIterator;
                private boolean completed = false;

                private synchronized void populate() {
                    this.listPartsResult = null;
                    this.partIterator = null;

                    try {
                        this.listPartsResult = listObjectParts(bucketName, objectName, uploadId,
                                nextPartNumberMarker);
                    } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException
                            | IOException | InvalidKeyException | NoResponseException | XmlPullParserException
                            | ErrorResponseException | InternalException e) {
                        this.error = new Result<>(null, e);
                    } finally {
                        if (this.listPartsResult != null) {
                            this.partIterator = this.listPartsResult.partList().iterator();
                        } else {
                            this.partIterator = new LinkedList<Part>().iterator();
                        }
                    }
                }

                @Override
                public boolean hasNext() {
                    if (this.completed) {
                        return false;
                    }

                    if (this.error == null && this.partIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.partIterator.hasNext()
                            && this.listPartsResult.isTruncated()) {
                        this.nextPartNumberMarker = this.listPartsResult.nextPartNumberMarker();
                        populate();
                    }

                    if (this.error != null) {
                        return true;
                    }

                    if (this.partIterator.hasNext()) {
                        return true;
                    }

                    this.completed = true;
                    return false;
                }

                @Override
                public Result<Part> next() {
                    if (this.completed) {
                        throw new NoSuchElementException();
                    }

                    if (this.error == null && this.partIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.partIterator.hasNext()
                            && this.listPartsResult.isTruncated()) {
                        this.nextPartNumberMarker = this.listPartsResult.nextPartNumberMarker();
                        populate();
                    }

                    if (this.error != null) {
                        this.completed = true;
                        return this.error;
                    }

                    if (this.partIterator.hasNext()) {
                        return new Result<>(this.partIterator.next(), null);
                    }

                    this.completed = true;
                    throw new NoSuchElementException();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:org.fusesource.camel.component.sap.SapIDocTestSupport.java

@Override
public void doPreSetup() throws Exception {
    super.doPreSetup();

    createMocks();/*from   w w  w . j av  a2s .c  o m*/

    /* Enhance Destination mock */
    when(mockDestination.createTID()).thenReturn(TEST_TID);

    /* Enhance IDoc Server mock */
    when(mockIDocServer.getRepositoryDestination()).thenReturn(TEST_DEST);
    when(mockIDocServer.getProgramID()).thenReturn(TEST_PROGRAM_ID);
    when(mockIDocServer.getIDocHandlerFactory()).thenReturn(mockIDocHandlerFactory);
    when(mockIDocServer.getIDocRepository()).thenReturn(mockIDocRepository);

    /* Enhance IDoc Repository  mock */
    when(mockIDocRepository.getName()).thenReturn(TEST_REPOSITORY);
    when(mockIDocRepository.getRootSegmentMetaData(TEST_IDOC_TYPE, TEST_IDOC_TYPE_EXTENSION,
            TEST_SYSTEM_RELEASE, TEST_APPLICATION_RELEASE)).thenReturn(mockRootSegmentMetaData);

    /* Enhance IDoc Factory mock */
    when(mockIDocFactory.createIDocDocument(mockIDocRepository, TEST_IDOC_TYPE, TEST_IDOC_TYPE_EXTENSION,
            TEST_SYSTEM_RELEASE, TEST_APPLICATION_RELEASE)).thenReturn(mockIDocDocument);
    when(mockIDocFactory.createIDocDocumentList(mockIDocRepository, TEST_IDOC_TYPE, TEST_IDOC_TYPE_EXTENSION,
            TEST_SYSTEM_RELEASE, TEST_APPLICATION_RELEASE)).thenReturn(mockIDocDocumentList);

    /* Enhance IDoc Document List mock */
    when(mockIDocDocumentList.iterator()).thenReturn(mockIDocDocumentListIterator);
    when(mockIDocDocumentList.getIDocType()).thenReturn(TEST_IDOC_TYPE);
    when(mockIDocDocumentList.getIDocTypeExtension()).thenReturn(TEST_IDOC_TYPE_EXTENSION);
    when(mockIDocDocumentList.getSystemRelease()).thenReturn(TEST_SYSTEM_RELEASE);
    when(mockIDocDocumentList.getApplicationRelease()).thenReturn(TEST_APPLICATION_RELEASE);
    when(mockIDocDocumentList.addNew()).thenReturn(mockIDocDocument);

    /* Enhance IDoc Document List Iterator mock */
    when(mockIDocDocumentListIterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
    when(mockIDocDocumentListIterator.next()).thenReturn(mockIDocDocument).thenReturn(mockIDocDocument)
            .thenThrow(new NoSuchElementException());

    enhanceRootSegment();
    enhanceLevel1Segment();
    enhanceLevel2Segment();
    enhanceLevel3Segment();
    enhanceIDocDocument();
}