List of usage examples for java.io UncheckedIOException getCause
@Override
public IOException getCause()
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
default void forEachMlist(String pathname, FTPFileFilter filter, IOConsumer<FTPFile> c) throws IOException { try {// w w w .j a v a 2 s . c o m forEachMlistDir(pathname, filter, c.guard()); } catch (UncheckedIOException ex) { throw ex.getCause(); } }
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
default void mlistFile(String pathname, IOConsumer<FTPFile> c) throws IOException { FTPFile file = mlistFile(pathname);//from w ww . j a va 2s .co m if (file != null) { try { c.accept(file); } catch (UncheckedIOException ex) { throw ex.getCause(); } } }
From source file:org.apache.storm.daemon.logviewer.handler.LogviewerLogPageHandler.java
/** * Provides a worker log file to view.//from w w w. java2s. c om * * @param fileName file to view * @param start start offset, can be null * @param length length to read in this page, can be null * @param grep search string if request is a result of the search, can be null * @param user username * @return HTML view page of worker log */ public Response logPage(String fileName, Integer start, Integer length, String grep, String user) throws IOException, InvalidRequestException { String rootDir = logRoot; if (resourceAuthorizer.isUserAllowedToAccessFile(user, fileName)) { workerLogs.setLogFilePermission(fileName); File file = new File(rootDir, fileName).getCanonicalFile(); String path = file.getCanonicalPath(); boolean isZipFile = path.endsWith(".gz"); File topoDir = file.getParentFile().getParentFile(); if (file.exists() && new File(rootDir).getCanonicalFile().equals(topoDir.getParentFile())) { SortedSet<File> logFiles; try { logFiles = Arrays.stream(topoDir.listFiles()) .flatMap(Unchecked .function(portDir -> DirectoryCleaner.getFilesForDir(portDir).stream())) .filter(File::isFile).collect(toCollection(TreeSet::new)); } catch (UncheckedIOException e) { throw e.getCause(); } List<String> filesStrWithoutFileParam = logFiles.stream().map(WorkerLogs::getTopologyPortWorkerLog) .filter(fileStr -> !StringUtils.equals(fileName, fileStr)).collect(toList()); List<String> reorderedFilesStr = new ArrayList<>(); reorderedFilesStr.addAll(filesStrWithoutFileParam); reorderedFilesStr.add(fileName); length = length != null ? Math.min(10485760, length) : LogviewerConstant.DEFAULT_BYTES_PER_PAGE; String logString; if (isTxtFile(fileName)) { logString = escapeHtml(start != null ? pageFile(path, start, length) : pageFile(path, length)); } else { logString = escapeHtml( "This is a binary file and cannot display! You may download the full file."); } long fileLength = isZipFile ? ServerUtils.zipFileSize(file) : file.length(); start = start != null ? start : Long.valueOf(fileLength - length).intValue(); List<DomContent> bodyContents = new ArrayList<>(); if (StringUtils.isNotEmpty(grep)) { String matchedString = String.join("\n", Arrays.stream(logString.split("\n")) .filter(str -> str.contains(grep)).collect(toList())); bodyContents.add(pre(matchedString).withId("logContent")); } else { DomContent pagerData = null; if (isTxtFile(fileName)) { pagerData = pagerLinks(fileName, start, length, Long.valueOf(fileLength).intValue(), "log"); } bodyContents.add(searchFileForm(fileName, "no")); // list all files for this topology bodyContents.add(logFileSelectionForm(reorderedFilesStr, fileName, "log")); if (pagerData != null) { bodyContents.add(pagerData); } bodyContents.add(downloadLink(fileName)); bodyContents.add(pre(logString).withClass("logContent")); if (pagerData != null) { bodyContents.add(pagerData); } } String content = logTemplate(bodyContents, fileName, user).render(); return LogviewerResponseBuilder.buildSuccessHtmlResponse(content); } else { return LogviewerResponseBuilder.buildResponsePageNotFound(); } } else { if (resourceAuthorizer.getLogUserGroupWhitelist(fileName) != null) { return LogviewerResponseBuilder.buildResponsePageNotFound(); } else { return LogviewerResponseBuilder.buildResponseUnautohrizedUser(user); } } }
From source file:org.codice.ddf.configuration.migration.ExportMigrationEntryImpl.java
private OutputStream getOutputStreamWithoutRecordingEntry() throws IOException { try {//w w w .j a v a 2 s. c om return outputStream.updateAndGet(os -> (os != null) ? os : context.getOutputStreamFor(this)); } catch (UncheckedIOException e) { throw e.getCause(); } }
From source file:org.geowebcache.storage.BlobStore.java
/** * If the given layer is cached, remove * @param layer/*from w ww.ja v a 2s. co m*/ * @throws StorageException */ public default boolean purgeOrphans(TileLayer layer) throws StorageException { // TODO maybe do purging based on gridset and format try { final List<ParameterFilter> parameterFilters = layer.getParameterFilters(); // Given known parameter mapping, figures out if the parameters need to be purged final Function<Map<String, String>, Boolean> parametersNeedPurge = parameters -> { return parameters.size() != parameterFilters.size() || // Should have the same number of parameters as the layer has filters parameterFilters.stream().allMatch(pfilter -> { // Do all the parameter filters on the layer consider their parameter legal final String key = pfilter.getKey(); final String value = parameters.get(key); if (Objects.isNull(value)) { return true; // No parameter for this filter so purge } return !pfilter.isFilteredValue(value); // purge if it's not a filtered value }); }; return getParametersMapping(layer.getName()).entrySet().stream().filter(parameterMapping -> { return parameterMapping.getValue().map(parametersNeedPurge).orElse(true); // Don't have the original values so purge }).map(Map.Entry::getKey) // The parameter id .map(id -> { try { return this.deleteByParametersId(layer.getName(), id); } catch (StorageException e) { throw new UncheckedIOException(e); } }).reduce((x, y) -> x || y) // OR results without short circuiting .orElse(false); } catch (UncheckedIOException ex) { if (ex.getCause() instanceof StorageException) { throw (StorageException) ex.getCause(); } else { throw ex; } } }
From source file:org.kitodo.filemanagement.locking.LockManagement.java
/** * Attempts to get locks on one or more files. There are only two results: * either, all locks can be granted, or none of the requested locks are * granted. In the former case, the conflicts map in the locking result is * empty, in the latter case it contains for each conflicting file the users * who hold a conflicting lock on the file. If no locks have been granted, * the call to {@code close()} on the locking result is meaningless, meaning * that leaving the try-with-resources statement will not throw an * exception. Just to mention that.// w ww.j av a 2 s . c o m * * @param user * A human-readable string that identifies the user or process * requesting the locks. This string will later be returned to * other users if they try to request a conflicting lock. * @param rights * existing user rights to be extended * @param requests * the locks to request * @return An object that manages allocated locks or provides information * about conflict originators in case of error. * @throws IOException * if the file does not exist or if an error occurs in disk * access, e.g. because the write permission for the directory * is missing */ public LockResult tryLock(String user, GrantedAccess rights, Map<URI, LockingMode> requests) throws IOException { try { return tryLock(new LockRequests(user, requests), rights); } catch (UncheckedIOException e) { throw e.getCause(); } }
From source file:org.nuxeo.ecm.core.io.download.DownloadServiceImpl.java
@Override public void downloadBlob(HttpServletRequest request, HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String, Serializable> extendedInfos, Boolean inline, Consumer<ByteRange> blobTransferer) throws IOException { Objects.requireNonNull(blob); // check blob permissions if (!checkPermission(doc, xpath, blob, reason, extendedInfos)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Permission denied"); return;/*from ww w . j a va 2 s . co m*/ } // check Blob Manager download link URI uri = redirectResolver.getURI(blob, UsageHint.DOWNLOAD, request); if (uri != null) { try { Map<String, Serializable> ei = new HashMap<>(); if (extendedInfos != null) { ei.putAll(extendedInfos); } ei.put("redirect", uri.toString()); logDownload(doc, xpath, filename, reason, ei); response.sendRedirect(uri.toString()); } catch (IOException ioe) { DownloadHelper.handleClientDisconnect(ioe); } return; } try { String digest = blob.getDigest(); if (digest == null) { digest = DigestUtils.md5Hex(blob.getStream()); } String etag = '"' + digest + '"'; // with quotes per RFC7232 2.3 response.setHeader("ETag", etag); // re-send even on SC_NOT_MODIFIED addCacheControlHeaders(request, response); String ifNoneMatch = request.getHeader("If-None-Match"); if (ifNoneMatch != null) { boolean match = false; if (ifNoneMatch.equals("*")) { match = true; } else { for (String previousEtag : StringUtils.split(ifNoneMatch, ", ")) { if (previousEtag.equals(etag)) { match = true; break; } } } if (match) { String method = request.getMethod(); if (method.equals("GET") || method.equals("HEAD")) { response.sendError(HttpServletResponse.SC_NOT_MODIFIED); } else { // per RFC7232 3.2 response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } } // regular processing if (StringUtils.isBlank(filename)) { filename = StringUtils.defaultIfBlank(blob.getFilename(), "file"); } String contentDisposition = DownloadHelper.getRFC2231ContentDisposition(request, filename, inline); response.setHeader("Content-Disposition", contentDisposition); response.setContentType(blob.getMimeType()); if (blob.getEncoding() != null) { response.setCharacterEncoding(blob.getEncoding()); } long length = blob.getLength(); response.setHeader("Accept-Ranges", "bytes"); String range = request.getHeader("Range"); ByteRange byteRange; if (StringUtils.isBlank(range)) { byteRange = null; } else { byteRange = DownloadHelper.parseRange(range, length); if (byteRange == null) { log.error("Invalid byte range received: " + range); } else { response.setHeader("Content-Range", "bytes " + byteRange.getStart() + "-" + byteRange.getEnd() + "/" + length); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); } } long contentLength = byteRange == null ? length : byteRange.getLength(); if (contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } logDownload(doc, xpath, filename, reason, extendedInfos); // execute the final download blobTransferer.accept(byteRange); } catch (UncheckedIOException e) { DownloadHelper.handleClientDisconnect(e.getCause()); } catch (IOException ioe) { DownloadHelper.handleClientDisconnect(ioe); } }