private String loadTemplateFromClasspath(final String filepath, final TaskView view) { try(InputStream in = view.getClass().getResourceAsStream(filepath)) { return in != null ? IOUtils.toString(in, UTF_8) : String.format("Template \"%s\" is missing.", filepath); } catch (IOException e) { LOG.error("Failed to load template from view from path \"{}\". Make sure your the template is on the classpath of your plugin", filepath, e); return String.format("Template \"%s\" failed to load.", filepath); } } }
@Override public String getVersion() { final InputStream is = getClass().getResourceAsStream("/com/alibaba/jvm/sandbox/version"); try { return IOUtils.toString(is); } catch (IOException e) { // impossible return "UNKNOW_VERSION"; } finally { IOUtils.closeQuietly(is); } } }
private Map<String, Object> getContextMap(int targetVersion) { try { String contextFile = String.format("/config-repo/contexts/%s.json", targetVersion); String contextJSON = IOUtils.toString(this.getClass().getResourceAsStream(contextFile), "UTF-8"); return JsonUtils.jsonToMap(contextJSON); } catch (Exception e) { LOGGER.debug(String.format("No context file present for target version '%s'.", targetVersion)); return null; } } }
@Test public void testToString_Reader() throws Exception { try (FileReader fin = new FileReader(m_testFile)) { final String out = IOUtils.toString(fin); assertNotNull(out); assertEquals("Wrong output size", FILE_SIZE, out.length()); } }
final String errorStream = IOUtils.toString(proc.getErrorStream(), StandardCharsets.UTF_8); if (null != errorStream && !errorStream.isEmpty()) { LOGGER.warn("Error from GrokAssembly: {}", errorStream); LOGGER.debug("{} is not a .NET assembly or executable and as such cannot be analyzed by dependency-check", dependency.getActualFilePath()); return; } else if (rc != 0) { LOGGER.debug("Return code {} from GrokAssembly; dependency-check is unable to analyze the library: {}", rc, dependency.getActualFilePath()); return; throw new AnalysisException(ioe); } catch (SAXException saxe) { LOGGER.error("----------------------------------------------------"); LOGGER.error("Failed to read the Assembly Analyzer results. " + "On some systems mono-runtime and mono-devel need to be installed."); LOGGER.error("----------------------------------------------------"); throw new AnalysisException("Couldn't parse Assembly Analyzer results (GrokAssembly)", saxe);
@Test public void testToString_ByteArray() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final byte[] in = IOUtils.toByteArray(fin); // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid. final String str = IOUtils.toString(in); assertEqualContent(in, str.getBytes()); } }
@Override public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { LOG.info("Trying to resolve XML entity with public ID [{}] and system ID [{}]", publicId, systemId); isValidSystemID(systemId); InputStream source = null; try { source = resolveFromClassPath(systemId); } catch (URISyntaxException | IOException exClasspath) { LOG.error("{}", exClasspath.getMessage()); LOG.debug("Exception: {}", exClasspath); try { source = resolveFromURL(systemId); } catch (IOException exURL) { MappingUtils.throwMappingException(exURL); } } InputStreamLSInput lsInput = null; try { lsInput = new InputStreamLSInput(publicId, systemId, baseURI, new StringReader(IOUtils.toString(source, Charset.forName("UTF-8")))); LOG.info("Resolved public ID [{}] and system ID [{}]", publicId, systemId); } catch (IOException ex) { MappingUtils.throwMappingException("Could not resolve bean-mapping XML Schema [" + systemId + "]", ex); } finally { IOUtils.closeQuietly(source); } return lsInput; }
private FeatureToggles readTogglesFromStream(InputStream streamForToggles, String kindOfToggle) { try { String existingToggleJSONContent = IOUtils.toString(streamForToggles); FeatureToggleFileContentRepresentation toggleContent = gson.fromJson(existingToggleJSONContent, FeatureToggleFileContentRepresentation.class); return new FeatureToggles(toggleContent.toggles); } catch (Exception e) { LOGGER.error("Failed to read {} toggles. Saying there are no toggles.", kindOfToggle, e); return new FeatureToggles(); } finally { IOUtils.closeQuietly(streamForToggles); } }
private void testToString_URI(final String encoding) throws Exception { final URI uri = m_testFile.toURI(); final String out = IOUtils.toString(uri, encoding); assertNotNull(out); assertEquals("Wrong output size", FILE_SIZE, out.length()); }
@Test public void testToString_URL() throws Exception { final URL url = m_testFile.toURI().toURL(); final String out = IOUtils.toString(url); assertNotNull(out); assertEquals("Wrong output size", FILE_SIZE, out.length()); }
public static String getFromHTTP(String url, Time timeout) throws Exception { final URL u = new URL(url); LOG.info("Accessing URL " + url + " as URL: " + u); final long deadline = timeout.toMilliseconds() + System.currentTimeMillis(); while (System.currentTimeMillis() <= deadline) { HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setConnectTimeout(100000); connection.connect(); if (Objects.equals(HttpResponseStatus.SERVICE_UNAVAILABLE, HttpResponseStatus.valueOf(connection.getResponseCode()))) { // service not available --> Sleep and retry LOG.debug("Web service currently not available. Retrying the request in a bit."); Thread.sleep(100L); } else { InputStream is; if (connection.getResponseCode() >= 400) { // error! LOG.warn("HTTP Response code when connecting to {} was {}", url, connection.getResponseCode()); is = connection.getErrorStream(); } else { is = connection.getInputStream(); } return IOUtils.toString(is, ConfigConstants.DEFAULT_CHARSET); } } throw new TimeoutException("Could not get HTTP response in time since the service is still unavailable."); }
if (schemaUrl.startsWith("http")) { schemaString = IOUtils.toString(new URI(schemaUrl), StandardCharsets.UTF_8); log.debug("Schema string is: " + schemaString); Schema schema = HiveAvroORCQueryGenerator.readSchemaFromString(schemaString); log.debug("Schema string is: " + schemaString); Schema schema = HiveAvroORCQueryGenerator.readSchemaFromString(schemaString); log.error(String.format("Failed to parse schema from schema string. Falling back to HDFS schema: %s", schemaString), e);
@Test public void testToByteArray_String() throws Exception { try (FileReader fin = new FileReader(m_testFile)) { // Create our String. Rely on testReaderToString() to make sure this is valid. final String str = IOUtils.toString(fin); final byte[] out = IOUtils.toByteArray(str); assertEqualContent(str.getBytes(), out); } }
log.debug("For " + this.getClass().getName() + ", unmarshall via binder"); log.debug("MOXy: checking whether binder workaround is necessary"); String contents = IOUtils.toString(is, "UTF-8"); IOUtils.closeQuietly(is); is = new ByteArrayInputStream(contents.getBytes("UTF-8")); log.debug("MOXy: yes, performing workaround"); log.error(e.getMessage(), e); throw e; log.error(ue.getMessage(), ue); throw ue; log.error(ue.getMessage(), ue); if (is.markSupported() ) { is.reset(); String theString = IOUtils.toString(is, "UTF-8");
private void testToString_URL(final String encoding) throws Exception { final URL url = m_testFile.toURI().toURL(); final String out = IOUtils.toString(url, encoding); assertNotNull(out); assertEquals("Wrong output size", FILE_SIZE, out.length()); }
/** * 获取LOGO * * @return LOGO */ public static String getLogo() { try { final InputStream logoIs = SandboxStringUtils.class.getResourceAsStream("/com/alibaba/jvm/sandbox/logo"); final String logo = IOUtils.toString(logoIs); IOUtils.closeQuietly(logoIs); return logo; } catch (IOException ioe) { // ignore... return StringUtils.EMPTY; } }
@Test public void testToString_InputStream() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final String out = IOUtils.toString(fin); assertNotNull(out); assertEquals("Not all bytes were read", 0, fin.available()); assertEquals("Wrong output size", FILE_SIZE, out.length()); } }
public static String bodyToText(byte[] bodyBytes, Headers headers) { try { if (HttpUtils.isGzipped(headers)) { GZIPInputStream gzIn = new GZIPInputStream(new ByteArrayInputStream(bodyBytes)); bodyBytes = IOUtils.toByteArray(gzIn); } return IOUtils.toString(bodyBytes, "UTF-8"); } catch (IOException e) { LOG.error("Error reading message body for debugging.", e); return "ERROR READING MESSAGE BODY!"; } }
@Override public boolean isReady(ContainerCreationStatus container) { String containerIp = this.getContainerIp(container.getContainerName()); if (ZALENIUM_RUNNING_LOCALLY) { containerIp = "localhost"; } if (containerIp != null) { try { URL statusUrl = new URL(String.format("http://%s:%s/wd/hub/status", containerIp, container.getNodePort())); String status = IOUtils.toString(statusUrl, StandardCharsets.UTF_8); String successMessage = "\"Node is running\""; if (status.contains(successMessage)) { return true; } } catch (IOException e) { logger.debug("Error while getting node status, probably the node is still starting up...", e); } } return false; }