public static void readJavaUtilLoggingConfigFromClasspath() { Stream inputStream = ReflectUtil.getResourceAsStream("logging.properties"); try { if (inputStream != null) { LogManager.LogManager.readConfiguration(inputStream); string redirectCommons = LogManager.LogManager.getProperty("redirect.commons.logging"); if ((!string.ReferenceEquals(redirectCommons, null)) && (!redirectCommons.Equals("false", StringComparison.OrdinalIgnoreCase))) { System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger"); } } } catch (Exception e) { throw new PvmException("couldn't initialize logging properly", e); } finally { IoUtil.closeSilently(inputStream); } }
/// <summary> /// Parse a camunda:resource attribute and loads the resource depending on the url scheme. /// Supported URL schemes are <code>classpath://</code> and <code>deployment://</code>. /// If the scheme is omitted <code>classpath://</code> is assumed. /// </summary> /// <param name="resourcePath"> the path to the resource to load </param> /// <param name="deployment"> the deployment to load resources from </param> /// <returns> the resource content as <seealso cref="string"/> </returns> public static string loadResourceContent(string resourcePath, DeploymentEntity deployment) { string[] pathSplit = resourcePath.Split("://", 2); string resourceType; if (pathSplit.Length == 1) { resourceType = "classpath"; } else { resourceType = pathSplit[0]; } string resourceLocation = pathSplit[pathSplit.Length - 1]; sbyte[] resourceBytes = null; if (resourceType.Equals("classpath")) { Stream resourceAsStream = null; try { resourceAsStream = ReflectUtil.getResourceAsStream(resourceLocation); if (resourceAsStream != null) { resourceBytes = IoUtil.readInputStream(resourceAsStream, resourcePath); } } finally { IoUtil.closeSilently(resourceAsStream); } } else if (resourceType.Equals("deployment")) { ResourceEntity resourceEntity = deployment.getResource(resourceLocation); if (resourceEntity != null) { resourceBytes = resourceEntity.Bytes; } } if (resourceBytes != null) { return(StringHelper.NewString(resourceBytes, Charset.forName("UTF-8"))); } else { throw LOG.cannotFindResource(resourcePath); } }
public static void writeStringToFile(string content, string filePath) { BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileStream(getFile(filePath), FileMode.Create, FileAccess.Write)); outputStream.write(content.GetBytes()); outputStream.flush(); } catch (Exception e) { throw LOG.exceptionWhileWritingToFile(filePath, e); } finally { IoUtil.closeSilently(outputStream); } }
public static string readClasspathResourceAsString(string resourceName) { Stream resourceAsStream = typeof(IoUtil).ClassLoader.getResourceAsStream(resourceName); if (resourceAsStream == null) { throw new ProcessEngineException("resource " + resourceName + " not found"); } MemoryStream outStream = new MemoryStream(); int next; sbyte[] result; sbyte[] buffer = new sbyte[1024]; BufferedInputStream inputStream = null; try { inputStream = new BufferedInputStream(resourceAsStream); while ((next = inputStream.read(buffer)) >= 0) { outStream.Write(buffer, 0, next); } result = outStream.toByteArray(); } catch (Exception e) { throw LOG.exceptionWhileReadingFile(resourceName, e); } finally { IoUtil.closeSilently(inputStream); IoUtil.closeSilently(outStream); } return(StringHelper.NewString(result, Charset.forName("UTF-8"))); }