public void buffer(byte read) { pos = -1; if (byteBuffered >= maxBufferSize) { log.debug(() -> "Buffer size " + maxBufferSize + " has been exceeded and the input stream " + "will not be repeatable. Freeing buffer memory"); bufferSizeOverflow = true; } else { bufferArray[byteBuffered++] = read; } }
public final void run(String[] args) { Options options = new Options(); Stream.of(optionsToAdd).forEach(options::addOption); CommandLineParser parser = new DefaultParser(); HelpFormatter help = new HelpFormatter(); try { CommandLine commandLine = parser.parse(options, args); run(commandLine); } catch (ParseException e) { log.error(() -> "Invalid input: " + e.getMessage()); help.printHelp(getClass().getSimpleName(), options); throw new Error(); } catch (Exception e) { log.error(() -> "Script execution failed.", e); throw new Error(); } }
private void closeStream(SdkHttpFullResponse response) { response.content().ifPresent(i -> { try { i.close(); } catch (IOException e) { log.warn(() -> "Error closing HTTP content.", e); } }); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { boolean channelInUse = getAttribute(ctx, ChannelAttributeKey.IN_USE).orElse(false); if (channelInUse) { ctx.fireExceptionCaught(cause); } else { ctx.close(); Optional<CompletableFuture<Void>> executeFuture = getAttribute(ctx, ChannelAttributeKey.EXECUTE_FUTURE_KEY); if (executeFuture.isPresent() && !executeFuture.get().isDone()) { log.error(() -> "An exception occurred on an channel (" + ctx.channel().id() + ") that was not in use, " + "but was associated with a future that wasn't completed. This indicates a bug in the " + "Java SDK, where a future was not completed while the channel was in use. The channel has " + "been closed, and the future will be completed to prevent any ongoing issues.", cause); executeFuture.get().completeExceptionally(cause); } else if (cause instanceof IOException) { log.debug(() -> "An I/O exception (" + cause.getMessage() + ") occurred on a channel (" + ctx.channel().id() + ") that was not in use. The channel has been closed. This is usually normal."); } else { log.warn(() -> "A non-I/O exception occurred on a channel (" + ctx.channel().id() + ") that was not in use. " + "The channel has been closed to prevent any ongoing issues.", cause); } } }
@Override public Socket connectSocket( final int connectTimeout, final Socket socket, final HttpHost host, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpContext context) throws IOException { log.trace(() -> String.format("Connecting to %s:%s", remoteAddress.getAddress(), remoteAddress.getPort())); Socket connectedSocket = super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context); if (connectedSocket instanceof SSLSocket) { return new SdkSslSocket((SSLSocket) connectedSocket); } return new SdkSocket(connectedSocket); }
public abstract class Cli { private final Logger log = Logger.loggerFor(Cli.class); private final Option[] optionsToAdd;
private void copyFile(Path source, Path destination) throws IOException { if (source != null && Files.isRegularFile(source)) { log.info(() -> "Copying " + source + " to " + destination); FileUtils.copyFile(source.toFile(), destination.toFile()); } } }
private void closeStream(SdkHttpFullResponse response) { response.content().ifPresent(i -> { try { i.close(); } catch (IOException e) { log.warn(() -> "Error closing HTTP content.", e); } }); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { boolean channelInUse = getAttribute(ctx, ChannelAttributeKey.IN_USE).orElse(false); if (channelInUse) { ctx.fireExceptionCaught(cause); } else { ctx.close(); Optional<CompletableFuture<Void>> executeFuture = getAttribute(ctx, ChannelAttributeKey.EXECUTE_FUTURE_KEY); if (executeFuture.isPresent() && !executeFuture.get().isDone()) { log.error(() -> "An exception occurred on an channel (" + ctx.channel().id() + ") that was not in use, " + "but was associated with a future that wasn't completed. This indicates a bug in the " + "Java SDK, where a future was not completed while the channel was in use. The channel has " + "been closed, and the future will be completed to prevent any ongoing issues.", cause); executeFuture.get().completeExceptionally(cause); } else if (cause instanceof IOException) { log.debug(() -> "An I/O exception (" + cause.getMessage() + ") occurred on a channel (" + ctx.channel().id() + ") that was not in use. The channel has been closed. This is usually normal."); } else { log.warn(() -> "A non-I/O exception occurred on a channel (" + ctx.channel().id() + ") that was not in use. " + "The channel has been closed to prevent any ongoing issues.", cause); } } }
@SuppressWarnings("unchecked") private T unmarshallResponse(SdkHttpFullResponse response) throws Exception { SdkStandardLogger.REQUEST_LOGGER.trace(() -> "Parsing service response XML."); T result = unmarshaller.unmarshall(pojoSupplier.apply(response), response); SdkStandardLogger.REQUEST_LOGGER.trace(() -> "Done parsing service response."); AwsResponseMetadata responseMetadata = generateResponseMetadata(response); return (T) result.toBuilder().responseMetadata(responseMetadata).build(); }
log.info(() -> "Got expected response: " + result); return result; } else if (whenToFail.test(result)) { log.info(() -> "Attempt " + unsuccessfulAttempt + " failed predicate."); } catch (RuntimeException e) { Throwable t = e instanceof CompletionException ? e.getCause() : e; log.info(() -> "Got expected exception: " + t.getClass().getSimpleName()); return null; log.info(() -> "Attempt " + unsuccessfulAttempt + " failed with an expected exception (" + t.getClass() + ")"); } else {
public void buffer(byte read) { pos = -1; if (byteBuffered >= maxBufferSize) { log.debug(() -> "Buffer size " + maxBufferSize + " has been exceeded and the input stream " + "will not be repeatable. Freeing buffer memory"); bufferSizeOverflow = true; } else { bufferArray[byteBuffered++] = read; } }
@Override public String getEnumValueName(String enumValue) { String result = enumValue; // Special cases result = result.replaceAll("textORcsv", "TEXT_OR_CSV"); // Split into words result = String.join("_", splitOnWordBoundaries(result)); // Enums should be upper-case result = StringUtils.upperCase(result); if (!result.matches("^[A-Z][A-Z0-9_]*$")) { String attempt = result; log.warn(() -> "Invalid enum member generated for input '" + enumValue + "'. Best attempt: '" + attempt + "' If this " + "enum is not customized out, the build will fail."); } return result; }
@SuppressWarnings("unchecked") private T unmarshallResponse(SdkHttpFullResponse response) throws Exception { SdkStandardLogger.REQUEST_LOGGER.trace(() -> "Parsing service response XML."); T result = unmarshaller.unmarshall(pojoSupplier.apply(response), response); SdkStandardLogger.REQUEST_LOGGER.trace(() -> "Done parsing service response."); AwsResponseMetadata responseMetadata = generateResponseMetadata(response); return (T) result.toBuilder().responseMetadata(responseMetadata).build(); }
log.info(() -> "Got expected response: " + result); return result; } else if (whenToFail.test(result)) { log.info(() -> "Attempt " + unsuccessfulAttempt + " failed predicate."); } catch (RuntimeException e) { Throwable t = e instanceof CompletionException ? e.getCause() : e; log.info(() -> "Got expected exception: " + t.getClass().getSimpleName()); return null; log.info(() -> "Attempt " + unsuccessfulAttempt + " failed with an expected exception (" + t.getClass() + ")"); } else {
public void buffer(byte[] src, int srcPos, int length) { pos = -1; if (byteBuffered + length > maxBufferSize) { log.debug(() -> "Buffer size " + maxBufferSize + " has been exceeded and the input stream " + "will not be repeatable. Freeing buffer memory"); bufferSizeOverflow = true; } else { System.arraycopy(src, srcPos, bufferArray, byteBuffered, length); byteBuffered += length; } }