use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class FileDownload method call.
@Override
public DownloadJob call() {
FileInputStream in = null;
OutputStream out = null;
try {
if (src.exists() && !src.isDirectory()) {
in = new FileInputStream(src);
out = txfr.openOutputStream(TransferOperation.DOWNLOAD, true, eventMetadata);
copy(in, out);
}
return this;
} catch (final IOException e) {
error = new TransferException("Failed to copy from: %s to: %s. Reason: %s", e, src, txfr, e.getMessage());
} finally {
closeQuietly(in);
closeQuietly(out);
}
return this;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class ZipPublish method writeArchive.
private Boolean writeArchive(final File dest, final String path) {
final boolean isJar = isJarOperation();
FileOutputStream fos = null;
ZipOutputStream zos = null;
ZipFile zf = null;
try {
fos = new FileOutputStream(dest);
zos = isJar ? new JarOutputStream(fos) : new ZipOutputStream(fos);
zf = isJar ? new JarFile(dest) : new ZipFile(dest);
final ZipEntry entry = zf.getEntry(path);
zos.putNextEntry(entry);
copy(stream, zos);
return true;
} catch (final IOException e) {
error = new TransferException("Failed to write path: %s to NEW archive: %s. Reason: %s", e, path, dest, e.getMessage());
} finally {
closeQuietly(zos);
closeQuietly(fos);
if (zf != null) {
try {
zf.close();
} catch (final IOException e) {
}
}
closeQuietly(stream);
}
return false;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class ZipPublish method rewriteArchive.
private Boolean rewriteArchive(final File dest, final String path) {
final boolean isJar = isJarOperation();
final File src = new File(dest.getParentFile(), dest.getName() + ".old");
dest.renameTo(src);
InputStream zin = null;
ZipFile zfIn = null;
FileOutputStream fos = null;
ZipOutputStream zos = null;
ZipFile zfOut = null;
try {
fos = new FileOutputStream(dest);
zos = isJar ? new JarOutputStream(fos) : new ZipOutputStream(fos);
zfOut = isJar ? new JarFile(dest) : new ZipFile(dest);
zfIn = isJar ? new JarFile(src) : new ZipFile(src);
for (final Enumeration<? extends ZipEntry> en = zfIn.entries(); en.hasMoreElements(); ) {
final ZipEntry inEntry = en.nextElement();
final String inPath = inEntry.getName();
try {
if (inPath.equals(path)) {
zin = stream;
} else {
zin = zfIn.getInputStream(inEntry);
}
final ZipEntry entry = zfOut.getEntry(inPath);
zos.putNextEntry(entry);
copy(stream, zos);
} finally {
closeQuietly(zin);
}
}
return true;
} catch (final IOException e) {
error = new TransferException("Failed to write path: %s to EXISTING archive: %s. Reason: %s", e, path, dest, e.getMessage());
} finally {
closeQuietly(zos);
closeQuietly(fos);
if (zfOut != null) {
try {
zfOut.close();
} catch (final IOException e) {
}
}
if (zfIn != null) {
try {
zfIn.close();
} catch (final IOException e) {
}
}
closeQuietly(stream);
}
return false;
}
use of org.commonjava.maven.galley.TransferException in project indy by Commonjava.
the class AutoProxDataManagerDecorator method checkValidity.
/**
* Validates the remote connection, produced from rule-set for given key,
* for a remote repo or group containing a remote. If:
*
* <ul>
* <li>rule.isValidationEnabled() == false, return true</li>
* <li>rule.getValidationRemote() == null, return true</li>
* <li>
* rule.getRemoteValidationPath() != null, validate remote.getUrl() + validationPath
* <ul>
* <li>if response code is 200 OK, then return true</li>
* <li>otherwise, return false</li>
* </ul>
* </li>
* </ul>
* @throws IndyDataException if the selected rule encounters an error while creating the new group/repository instance(s).
*/
private boolean checkValidity(final StoreKey key) throws IndyDataException {
if (catalog.isValidationEnabled(key)) {
try {
final RemoteRepository validationRepo = catalog.createValidationRemote(key);
if (validationRepo == null) {
logger.info("No validation repository was created: assuming {} is valid.", key);
return true;
}
String path = catalog.getRemoteValidationPath(key);
if (path == null) {
path = PathUtils.ROOT;
}
logger.debug("\n\n\n\n\n[AutoProx] Checking path: {} under remote URL: {}", path, validationRepo.getUrl());
boolean result = false;
try {
result = transferManager.exists(new ConcreteResource(LocationUtils.toLocation(validationRepo), path));
} catch (final TransferException e) {
logger.warn("[AutoProx] Cannot connect to target repository: '{}'. Reason: {}", validationRepo, e.getMessage());
logger.debug("[AutoProx] exception from validation attempt for: " + validationRepo, e);
}
logger.debug("Validation result for: {} is: {}", validationRepo, result);
return result;
} catch (final AutoProxRuleException e) {
throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
}
}
return true;
}
Aggregations