use of org.apache.commons.lang3.StringUtils.EMPTY in project azure-gradle-plugins by lenala.
the class AnnotationHandlerImpl method patchStorageBinding.
private void patchStorageBinding(final Method method, final List<BaseBinding> bindings) {
final Optional<Annotation> storageAccount = Arrays.stream(method.getAnnotations()).filter(a -> a instanceof StorageAccount).findFirst();
if (storageAccount.isPresent()) {
logger.quiet("StorageAccount annotation found.");
final String connectionString = ((StorageAccount) storageAccount.get()).value();
bindings.stream().forEach(b -> {
if (b instanceof StorageBaseBinding) {
final StorageBaseBinding sb = (StorageBaseBinding) b;
// Override storage bindings with empty connection
if (StringUtils.isEmpty(sb.getConnection())) {
sb.setConnection(connectionString);
}
}
});
} else {
logger.quiet("No StorageAccount annotation found.");
}
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project codeforces-commons by Codeforces.
the class ZipUtil method formatZipArchiveContentForView.
/**
* Formats content of the ZIP-archive for view and returns result as UTF-8 bytes. The {@code truncated} flag
* indicates that the length of returned view was restricted by {@code maxLength} parameter.
*
* @param zipFile ZIP-archive to format
* @param maxLength maximal allowed length of result
* @param maxEntryLineCount maximal allowed number of content lines to display for a single ZIP-archive entry
* @param maxEntryLineLength maximal allowed length of ZIP-archive entry content line
* @param entryListHeaderPattern pattern of entry list header; parameters: {@code fileName}, {@code filePath}, {@code entryCount}
* @param entryListItemPattern pattern of entry list item; parameters: {@code entryName}, {@code entrySize}, {@code entryIndex} (1-based)
* @param entryListItemSeparatorPattern pattern of entry list separator
* @param entryListCloserPattern pattern of entry list closer; parameters: {@code fileName}, {@code filePath}
* @param entryContentHeaderPattern pattern of entry content header; parameters: {@code entryName}, {@code entrySize}
* @param entryContentLinePattern pattern of entry content line; parameters: {@code entryLine}
* @param entryContentLineSeparatorPattern pattern of entry content separator
* @param entryContentCloserPattern pattern of entry content closer; parameters: {@code entryName}
* @param binaryEntryContentPlaceholderPattern pattern of binary entry content placeholder; parameters: {@code entrySize}
* @param emptyZipFilePlaceholderPattern pattern of empty (no entries) ZIP-file placeholder; parameters: {@code fileName}, {@code filePath}
* @return formatted view of ZIP-archive
* @throws IOException if {@code zipFile} is not a correct ZIP-archive or any other I/O-error has been occured
* @see String#format(String, Object...)
*/
@SuppressWarnings("OverlyLongMethod")
@Nonnull
public static FileUtil.FirstBytes formatZipArchiveContentForView(File zipFile, int maxLength, int maxEntryLineCount, int maxEntryLineLength, @Nullable String entryListHeaderPattern, @Nullable String entryListItemPattern, @Nullable String entryListItemSeparatorPattern, @Nullable String entryListCloserPattern, @Nullable String entryContentHeaderPattern, @Nullable String entryContentLinePattern, @Nullable String entryContentLineSeparatorPattern, @Nullable String entryContentCloserPattern, @Nullable String binaryEntryContentPlaceholderPattern, @Nullable String emptyZipFilePlaceholderPattern) throws IOException {
entryListHeaderPattern = StringUtil.nullToDefault(entryListHeaderPattern, "ZIP-file entries {\n");
entryListItemPattern = StringUtil.nullToDefault(entryListItemPattern, " %3$03d. %1$s (%2$d B)");
entryListItemSeparatorPattern = StringUtil.nullToDefault(entryListItemSeparatorPattern, "\n");
entryListCloserPattern = StringUtil.nullToDefault(entryListCloserPattern, "\n}\n\n");
entryContentHeaderPattern = StringUtil.nullToDefault(entryContentHeaderPattern, "Entry %1$s (%2$d B) {\n");
entryContentLinePattern = StringUtil.nullToDefault(entryContentLinePattern, " %1$s");
entryContentLineSeparatorPattern = StringUtil.nullToDefault(entryContentLineSeparatorPattern, "\n");
entryContentCloserPattern = StringUtil.nullToDefault(entryContentCloserPattern, "\n} // %1$s\n\n");
binaryEntryContentPlaceholderPattern = StringUtil.nullToDefault(binaryEntryContentPlaceholderPattern, " *** BINARY DATA (%1$d B) ***");
emptyZipFilePlaceholderPattern = StringUtil.nullToDefault(emptyZipFilePlaceholderPattern, "Empty ZIP-file.");
try {
Charset charset = StandardCharsets.UTF_8;
ZipFile internalZipFile = new ZipFile(zipFile);
List<?> fileHeaders = internalZipFile.getFileHeaders();
int headerCount = fileHeaders.size();
if (headerCount <= 0) {
return formatEmptyZipFilePlaceholder(zipFile, maxLength, emptyZipFilePlaceholderPattern, charset);
}
MutableBoolean truncated = new MutableBoolean(Boolean.FALSE);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
CountingOutputStream countingOutputStream = new CountingOutputStream(byteArrayOutputStream);
byte[] entryListHeaderBytes = String.format(entryListHeaderPattern, zipFile.getName(), zipFile.getPath(), headerCount).getBytes(charset);
if (!writeBytesForView(countingOutputStream, entryListHeaderBytes, maxLength, truncated)) {
throw new IllegalArgumentException(String.format("Argument 'maxLength' (%d) is less than the length of entry list header '%s' (%d bytes).", maxLength, new String(entryListHeaderBytes, charset), entryListHeaderBytes.length));
}
fileHeaders.sort(Comparator.comparing(header -> ((FileHeader) header).getFileName()));
for (int headerIndex = 0; headerIndex < headerCount; ++headerIndex) {
FileHeader header = (FileHeader) fileHeaders.get(headerIndex);
String fileName = header.getFileName();
String entryListItemAppendix = headerIndex == headerCount - 1 ? String.format(entryListCloserPattern, zipFile.getName(), zipFile.getPath()) : entryListItemSeparatorPattern;
byte[] entryListItemBytes = (String.format(entryListItemPattern, fileName, header.getUncompressedSize(), headerIndex + 1) + entryListItemAppendix).getBytes(charset);
if (!writeBytesForView(countingOutputStream, entryListItemBytes, maxLength, truncated)) {
break;
}
}
for (int headerIndex = 0; headerIndex < headerCount; ++headerIndex) {
FileHeader header = (FileHeader) fileHeaders.get(headerIndex);
if (header.isDirectory()) {
continue;
}
formatAndAppendEntryContent(countingOutputStream, maxLength, truncated, charset, internalZipFile, header, maxEntryLineCount, maxEntryLineLength, entryContentHeaderPattern, entryContentLinePattern, entryContentLineSeparatorPattern, entryContentCloserPattern, binaryEntryContentPlaceholderPattern);
if (truncated.booleanValue()) {
break;
}
}
return new FileUtil.FirstBytes(truncated.booleanValue(), byteArrayOutputStream.toByteArray());
} catch (ZipException e) {
throw new IOException("Can't format ZIP-file for view.", e);
}
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project nifi-registry by apache.
the class CryptoKeyLoader method extractKeyFromBootstrapFile.
/**
* Returns the key (if any) used to encrypt sensitive properties.
* The key extracted from the bootstrap.conf file at the specified location.
*
* @param bootstrapPath the path to the bootstrap file
* @return the key in hexadecimal format, or {@link CryptoKeyProvider#EMPTY_KEY} if the key is null or empty
* @throws IOException if the file is not readable
*/
public static String extractKeyFromBootstrapFile(String bootstrapPath) throws IOException {
File bootstrapFile;
if (StringUtils.isBlank(bootstrapPath)) {
logger.error("Cannot read from bootstrap.conf file to extract encryption key; location not specified");
throw new IOException("Cannot read from bootstrap.conf without file location");
} else {
bootstrapFile = new File(bootstrapPath);
}
String keyValue;
if (bootstrapFile.exists() && bootstrapFile.canRead()) {
try (Stream<String> stream = Files.lines(Paths.get(bootstrapFile.getAbsolutePath()))) {
Optional<String> keyLine = stream.filter(l -> l.startsWith(BOOTSTRAP_KEY_PREFIX)).findFirst();
if (keyLine.isPresent()) {
keyValue = keyLine.get().split("=", 2)[1];
keyValue = checkHexKey(keyValue);
} else {
keyValue = CryptoKeyProvider.EMPTY_KEY;
}
} catch (IOException e) {
logger.error("Cannot read from bootstrap.conf file at {} to extract encryption key", bootstrapFile.getAbsolutePath());
throw new IOException("Cannot read from bootstrap.conf", e);
}
} else {
logger.error("Cannot read from bootstrap.conf file at {} to extract encryption key -- file is missing or permissions are incorrect", bootstrapFile.getAbsolutePath());
throw new IOException("Cannot read from bootstrap.conf");
}
if (CryptoKeyProvider.EMPTY_KEY.equals(keyValue)) {
logger.info("No encryption key present in the bootstrap.conf file at {}", bootstrapFile.getAbsolutePath());
}
return keyValue;
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project timbuctoo by HuygensING.
the class TabularUpload method upload.
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@POST
public Response upload(@FormDataParam("file") final InputStream rdfInputStream, @FormDataParam("file") final FormDataBodyPart body, @FormDataParam("file") final FormDataContentDisposition fileInfo, @FormDataParam("fileMimeTypeOverride") final MediaType mimeTypeOverride, FormDataMultiPart formData, @HeaderParam("authorization") final String authHeader, @PathParam("userId") final String ownerId, @PathParam("dataSetId") final String dataSetId, @QueryParam("forceCreation") boolean forceCreation) throws DataStoreCreationException, FileStorageFailedException, ExecutionException, InterruptedException, LogStorageFailedException {
final Either<Response, Response> result = authCheck.getOrCreate(authHeader, ownerId, dataSetId, forceCreation).flatMap(userAndDs -> authCheck.hasAdminAccess(userAndDs.getLeft(), userAndDs.getRight())).map(userAndDs -> {
final MediaType mediaType = mimeTypeOverride == null ? body.getMediaType() : mimeTypeOverride;
Optional<Loader> loader = LoaderFactory.createFor(mediaType.toString(), formData.getFields().entrySet().stream().filter(entry -> entry.getValue().size() > 0).filter(entry -> entry.getValue().get(0) != null).filter(entry -> MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, entry.getValue().get(0).getMediaType())).collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get(0).getValue())));
if (!loader.isPresent()) {
return errorResponseHelper.error(400, "We do not support the mediatype '" + mediaType + "'. Make sure to add the correct mediatype to the file " + "parameter. In curl you'd use `-F \"file=@<filename>;type=<mediatype>\"`. In a webbrowser you probably " + "have no way of setting the correct mimetype. So you can use a special parameter to override it: " + "`formData.append(\"fileMimeTypeOverride\", \"<mimetype>\");`");
}
final DataSet dataSet = userAndDs.getRight();
ImportManager importManager = dataSet.getImportManager();
if (StringUtils.isBlank(fileInfo.getName())) {
return Response.status(400).entity("filename cannot be empty.").build();
}
try {
String fileToken = importManager.addFile(rdfInputStream, fileInfo.getFileName(), mediaType);
Future<ImportStatus> promise = importManager.generateLog(dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getBaseUri(), new TabularRdfCreator(loader.get(), fileToken, fileInfo.getFileName()));
return handleImportManagerResult(promise);
} catch (FileStorageFailedException | LogStorageFailedException e) {
LOG.error("Tabular upload failed", e);
return Response.serverError().build();
}
});
if (result.isLeft()) {
return result.getLeft();
} else {
return result.get();
}
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project mule by mulesoft.
the class DefaultArchiveDeployer method deployPackagedArtifact.
@Override
public T deployPackagedArtifact(URI artifactAchivedUri, Optional<Properties> appProperties) throws DeploymentException {
Optional<T> foundMatchingArtifact = empty();
try {
File artifactLocation = installArtifact(artifactAchivedUri);
T artifact;
try {
artifact = createArtifact(artifactLocation, appProperties);
trackArtifact(artifact);
} catch (Throwable t) {
String artifactName = artifactLocation.getName();
// error text has been created by the deployer already
logDeploymentFailure(t, artifactName);
foundMatchingArtifact.ifPresent(a -> deploymentListener.onRedeploymentFailure(a.getArtifactName(), t));
addZombieFile(artifactName, artifactLocation);
deploymentListener.onDeploymentFailure(artifactName, t);
throw t;
}
deployArtifact(artifact, appProperties);
foundMatchingArtifact.ifPresent(a -> deploymentListener.onRedeploymentSuccess(a.getArtifactName()));
return artifact;
} catch (Throwable t) {
foundMatchingArtifact.ifPresent(a -> deploymentListener.onRedeploymentFailure(a.getArtifactName(), t));
if (t instanceof DeploymentException) {
// re-throw
throw ((DeploymentException) t);
}
final String msg = "Failed to deploy from URI: " + artifactAchivedUri;
throw new DeploymentException(createStaticMessage(msg), t);
}
}
Aggregations