@Override public String initHtmlTemplate() { try (InputStream in = ResourceBase.class.getResource("html/defaultWizardStatus.html").openStream()) { return IOUtility.readString(in, "iso-8859-1"); } catch (Exception t) { throw new ProcessingException("Unexpected", t); } }
public BufferedServletInputStream(InputStream source) { this(IOUtility.readBytes(source)); }
/** * Reads a {@link String} from the specified {@code URL} resource. */ public String readResourceAsString(URL url) throws IOException { assertNotNull("Invalid expected resource URL", url); return IOUtility.readStringUTF8(url.openStream()); }
protected BufferedServletInputStream ensureBufferedStream() throws IOException { if (m_buf == null) { byte[] gzipped = IOUtility.readBytes(super.getInputStream(), super.getContentLength()); m_compressedLength = gzipped.length; m_buf = new BufferedServletInputStream(IOUtility.uncompressGzip(gzipped)); m_uncompressedLength = m_buf.getLength(); } return m_buf; }
public String toPath() { String encodedFilename = IOUtility.urlEncode(getFileName()); // / was encoded by %2F, revert this encoding otherwise filename doesn't look nice in browser download // Example for filesnames containing a /: // - relative reference from a unzipped zip file // - another path segment was explicitly added to distinguish between same filenames encodedFilename = encodedFilename.replace("%2F", "/"); return PATH_PREFIX + '/' + getUiSession().getUiSessionId() + '/' + getJsonAdapterId() + '/' + encodedFilename; }
protected JSONObject getJson(String pathInfo) throws IOException { URL jsonUrl = getJsonFileUrl(pathInfo); if (jsonUrl == null) { LOG.warn("Failed to load resource {}", pathInfo); return null; } byte[] jsonBytes = IOUtility.readFromUrl(jsonUrl); String json = new String(jsonBytes, StandardCharsets.UTF_8); return new JSONObject(json); } }
byte[] gzipped; if (minimumLengthToCompress >= 0 && m_uncompressedLength >= minimumLengthToCompress) { gzipped = IOUtility.compressGzip(raw); res.addHeader(GzipServletFilter.CONTENT_ENCODING, GzipServletFilter.GZIP); compressed = true;
protected String calcContentDispositionHeaderValue(String originalFilename) { // Internet Explorer 11 cannot parse names with characters 0x00-0x1F, neither in filename= nor encoded in filename*= // Note: 0x00-0x1F are the same in UTF-16 and ISO-8859-1, thus replacing them here is safe. if (originalFilename != null) { originalFilename = originalFilename.replaceAll("[\\x00-\\x1F]", ""); } if (StringUtility.isNullOrEmpty(originalFilename)) { originalFilename = DEFAULT_FILENAME; } String isoFilename = getIsoFilename(originalFilename); //remove ", because it is used to encapsulate the file name isoFilename = StringUtility.replace(isoFilename, "\"", ""); if (StringUtility.isNullOrEmpty(isoFilename)) { // in case no valid character remains isoFilename = DEFAULT_FILENAME; } return "attachment; filename=\"" + isoFilename + "\"; filename*=utf-8''" + IOUtility.urlEncode(originalFilename); }
@SuppressWarnings("squid:S1149") protected void replaceIncludeTags() throws IOException { // <scout:include template="no-script.html" /> Matcher m = PATTERN_INCLUDE_TAG.matcher(m_workingContent); StringBuffer sb = new StringBuffer(); while (m.find()) { String includeName = m.group(1); URL includeUrl = BEANS.get(IWebContentService.class).getWebContentResource("/includes/" + includeName); if (includeUrl == null) { throw new IOException("Could not resolve include '" + includeName + "'"); } else { byte[] includeContent = IOUtility.readFromUrl(includeUrl); String replacement = new String(includeContent, StandardCharsets.UTF_8); // Ensure exactly 1 newline before and after the replacement (to improve readability in resulting document) replacement = "\n" + replacement.trim() + "\n"; m.appendReplacement(sb, replacement); LOG.trace("Resolved include '{}'", includeName); } } m.appendTail(sb); m_workingContent = sb.toString(); }
protected String initHtmlDrillDown() { try (InputStream in = getClass().getResource("org/eclipse/scout/rt/client/mobile/html/MobileTableDrillDown.html").openStream()) { return IOUtility.readString(in, "iso-8859-1"); } catch (IOException e) { throw new ProcessingException("Exception while loading html cell template for mobile table", e); } }
public BufferedServletInputStream(InputStream source, int len) { this(IOUtility.readBytes(source, len)); // maybe read the data async? }
protected void handleModelOpenUri(BinaryResource res, IOpenUriAction openUriAction) { String filename = ObjectUtility.nvl(res.getFilename(), "binaryData"); String filenameEncoded = IOUtility.urlEncode(filename); // add another path segment to filename to distinguish between different resources // with the same filename (also makes hash collisions irrelevant). long counter = RESOURCE_COUNTER.getAndIncrement(); filenameEncoded = counter + "/" + filenameEncoded; BinaryResourceHolder holder = new BinaryResourceHolder(res); if (openUriAction == OpenUriAction.DOWNLOAD) { holder.addHttpResponseInterceptor(new DownloadHttpResponseInterceptor(res.getFilename())); } m_downloads.put(filenameEncoded, holder, openUriAction); String downloadUrl = BinaryResourceUrlUtility.createDynamicAdapterResourceUrl(this, filenameEncoded); handleModelOpenUri(downloadUrl, openUriAction); }
jsonData = IOUtility.readStringUTF8(in);
protected ScriptOutput processLibrary(String pathInfo, ScriptSource script, boolean compileAndMinify) throws IOException { if (!ObjectUtility.isOneOf(script.getNodeType(), NodeType.LIBRARY, NodeType.LIBRARY_MINIFIED)) { throw new IOException(script.getRequestPath() + " / " + script.getURL() + ": expected " + NodeType.LIBRARY + " or " + NodeType.LIBRARY_MINIFIED + ", but got " + script.getNodeType()); } long lastModified = script.getURL().openConnection().getLastModified(); String libraryContent = new String(IOUtility.readFromUrl(script.getURL()), StandardCharsets.UTF_8); // only minfy if not already minified if (compileAndMinify && script.getNodeType() != NodeType.LIBRARY_MINIFIED) { libraryContent = compileAndMinifyContent(script.getFileType(), libraryContent); } return new ScriptOutput(pathInfo, libraryContent.getBytes(StandardCharsets.UTF_8), lastModified); }
protected String initHtmlCellTemplate() { try (InputStream in = getClass().getResource("org/eclipse/scout/rt/client/mobile/html/MobileTableCellContent.html").openStream()) { return IOUtility.readString(in, "iso-8859-1"); } catch (IOException e) { throw new ProcessingException("Exception while loading html cell template for mobile table", e); } }
protected IconSpec findIconSpec(String[] relativePaths, String[] iconNames) { if (relativePaths != null && relativePaths.length > 0) { for (int i = 0; i < relativePaths.length; i++) { String relativePath = relativePaths[i]; String iconName = iconNames[i]; URL url = findResource(relativePath); if (url != null) { try (InputStream in = url.openStream()) { IconSpec iconSpec = new IconSpec(); byte[] content = IOUtility.readBytes(in); if (content != null) { iconSpec.setContent(content); } iconSpec.setName(iconName); return iconSpec; } catch (Exception e) { LOG.error("could not read input stream from url '{}'.", url, e); } } } } return null; }
String content = new String(IOUtility.readFromUrl(script.getURL()), StandardCharsets.UTF_8); Matcher mat = matcherForScriptType(script, content); int pos = 0; switch (includeFragment.getNodeType()) { case SRC_FRAGMENT: { replacement = new String(IOUtility.readFromUrl(includeFragment.getURL()), StandardCharsets.UTF_8); lastModified = Math.max(lastModified, includeFragment.getURL().openConnection().getLastModified()); break;
protected String initHtmlDrillDownButton() { try (InputStream in = getClass().getResource("org/eclipse/scout/rt/client/mobile/html/MobileTableDrillDownButton.html").openStream()) { return IOUtility.readString(in, "iso-8859-1"); } catch (IOException e) { throw new ProcessingException("Exception while loading html cell template for mobile table", e); } }
content = IOUtility.readBytes(in);
String content = new String(IOUtility.readFromUrl(script.getURL()), StandardCharsets.UTF_8); int pos = 0; Matcher mat = matcherForScriptType(script, content);