org.mule.runtime.core.api.util.IOUtils类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.mule.runtime.core.api.util.IOUtils类的一些代码示例,展示了IOUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils类的具体详情如下:
包路径:org.mule.runtime.core.api.util.IOUtils
类名称:IOUtils

IOUtils介绍

[英]Mule input/output utilities.
[中]Mule输入/输出实用程序。

代码示例

代码示例来源:origin: mulesoft/mule

private String getDescriptorContent(File jsonFile) {
 try (InputStream stream = new FileInputStream(jsonFile)) {
  return IOUtils.toString(stream);
 } catch (IOException e) {
  throw new IllegalArgumentException(format("Could not read extension describer on artifact '%s'",
                       jsonFile.getAbsolutePath()),
                    e);
 }
}

代码示例来源:origin: mulesoft/mule

@Test
 public void decodeWithoutUnzipping() throws Exception {
  final String payload = RandomStringUtils.randomAlphabetic(1024);
  ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(payload.getBytes());
  GZIPCompressorInputStream gzipCompressorInputStream = new GZIPCompressorInputStream(byteArrayInputStream);

  String encoded = Base64.encodeBytes(IOUtils.toByteArray(gzipCompressorInputStream), Base64.DONT_BREAK_LINES);
  GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(Base64.decodeWithoutUnzipping(encoded)));

  assertThat(IOUtils.toString(gzipInputStream), is(payload));
 }
}

代码示例来源:origin: mulesoft/mule

protected String loadResourceAsString(String resourceName) throws IOException {
 return IOUtils.getResourceAsString(resourceName, getClass());
}

代码示例来源:origin: mulesoft/mule

MulePluginBasedLoaderFinder(InputStream json) {
 try {
  this.mulePlugin = mulePluginSerializer.deserialize(IOUtils.toString(json));
 } finally {
  closeQuietly(json);
 }
}

代码示例来源:origin: mulesoft/mule

private <T> T createCustomInstance(String classLocation) {
 InputStream classStream = null;
 try {
  classStream = this.getClass().getResourceAsStream(classLocation);
  byte[] classBytes = IOUtils.toByteArray(classStream);
  classStream.close();
  Class clazz = this.defineClass(null, classBytes, 0, classBytes.length);
  return (T) clazz.newInstance();
 } catch (Exception e) {
  throw new RuntimeException("Can not create instance from resource: " + classLocation, e);
 } finally {
  closeQuietly(classStream);
 }
}

代码示例来源:origin: mulesoft/mule

public static boolean compare(InputStream input1, InputStream input2) {
  byte[] bytes1 = IOUtils.toByteArray(input1);
  byte[] bytes2 = IOUtils.toByteArray(input2);
  return Arrays.equals(bytes1, bytes2);
 }
}

代码示例来源:origin: mulesoft/mule

private void discoverCustomPropertyEditor() {
  customPropertyEditorsCache = new HashMap<>();

  for (ClassLoader classLoader : resolveContextArtifactPluginClassLoaders()) {
   // Look for any editors needed by extensions
   try {
    Enumeration<URL> urls = classLoader.getResources(CUSTOM_PROPERTY_EDITOR_RESOURCE_NAME);
    while (urls.hasMoreElements()) {
     URL url = urls.nextElement();
     Properties props = new Properties();
     InputStream stream = url.openStream();
     try {
      props.load(stream);
      for (Map.Entry<Object, Object> entry : props.entrySet()) {
       String target = (String) entry.getKey();
       String editor = (String) entry.getValue();
       Class<?> requiredType = classLoader.loadClass(target);
       Class<PropertyEditor> propertyEditorClass = (Class<PropertyEditor>) classLoader.loadClass(editor);
       customPropertyEditorsCache.put(requiredType, propertyEditorClass);
      }
     } finally {
      closeQuietly(stream);
     }
    }
   } catch (Exception e) {
    throw new IllegalStateException("Error loading custom property editors", e);
   }
  }
 }
}

代码示例来源:origin: mulesoft/mule

private File getGenerationTargetDirectory() {
 URL url = getResourceAsUrl(getEffectiveConfigFile(), getClass(), true, true);
 File targetDirectory = new File(FileUtils.toFile(url).getParentFile(), "META-INF");
 if (!targetDirectory.exists() && !targetDirectory.mkdir()) {
  throw new RuntimeException("Could not create target directory " + targetDirectory.getAbsolutePath());
 }
 return targetDirectory;
}

代码示例来源:origin: org.mule.runtime/mule-core

private String handleStream(InputStream input) {
 String string;
 try {
  string = IOUtils.toString(input);
 } finally {
  closeQuietly(input);
 }
 return string;
}

代码示例来源:origin: mulesoft/mule

/**
 * {@inheritDoc}
 */
@Override
protected byte[] doSerialize(Object object) throws Exception {
 //TODO: MULE-11939
 if (object instanceof CursorStreamProvider) {
  try (CursorStream cursor = ((CursorStreamProvider) object).openCursor()) {
   object = toByteArray(cursor);
  }
 }
 validateForSerialization(object);
 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512);
 try (ObjectOutputStream out = new ArtifactClassLoaderObjectOutputStream(classLoaderRepository, outputStream)) {
  out.writeObject(object);
 } catch (IOException ex) {
  throw new SerializationException("Cannot serialize object", ex);
 }
 return outputStream.toByteArray();
}

代码示例来源:origin: org.mule.runtime/mule-core

public static synchronized void copyStreamToFile(InputStream input, File destination) throws IOException {
 if (destination.exists() && !destination.canWrite()) {
  throw new IOException("Destination file does not exist or is not writeable");
 }
 try {
  FileOutputStream output = new FileOutputStream(destination);
  try {
   copy(input, output);
  } finally {
   IOUtils.closeQuietly(output);
  }
 } finally {
  IOUtils.closeQuietly(input);
 }
}

代码示例来源:origin: org.mule.runtime/mule-core

private byte[] handleStream(InputStream input) {
  try {
   return toByteArray(input);
  } finally {
   closeQuietly(input);
  }
 }
}

代码示例来源:origin: mulesoft/mule

private void setupUserManagerFactory(FtpServerFactory serverFactory) throws IOException, URISyntaxException {
 PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
 URL usersFile = IOUtils.getResourceAsUrl("users.properties", getClass());
 if (usersFile == null) {
  throw new IOException("users.properties file not found in the classpath");
 }
 userManagerFactory.setFile(new File(usersFile.toURI()));
 serverFactory.setUserManager(userManagerFactory.createUserManager());
}

代码示例来源:origin: mulesoft/mule

@Override
public MessageDispatcher connect() throws ConnectionException {
 return request -> {
  try {
   URL resource = Thread.currentThread().getContextClassLoader().getResource("test-http-response.xml");
   String response = String.format(IOUtils.toString(resource.openStream()), getResponseWord());
   return new DispatchingResponse(new ByteArrayInputStream(response.getBytes()), singletonMap("Content-Type", "text/xml"));
  } catch (Exception e) {
   throw new RuntimeException("Something went wrong when getting fake test response", e);
  }
 };
}

代码示例来源:origin: org.mule.connectors/mule-ftp-connector

protected String toString(Object value) {
 if (value == null) {
  return null;
 }
 if (value instanceof Message) {
  value = ((Message) value).getPayload().getValue();
 }
 if (value instanceof String) {
  return (String) value;
 }
 InputStream inputStream;
 if (value instanceof CursorStreamProvider) {
  inputStream = ((CursorStreamProvider) value).openCursor();
 } else if (value instanceof InputStream) {
  inputStream = (InputStream) value;
 } else {
  throw new IllegalArgumentException("Result was not of expected type");
 }
 try {
  return IOUtils.toString(inputStream);
 } finally {
  closeQuietly(inputStream);
 }
}

代码示例来源:origin: org.mule.runtime/mule-core-tests

@Test
 public void decodeWithoutUnzipping() throws Exception {
  final String payload = RandomStringUtils.randomAlphabetic(1024);
  ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(payload.getBytes());
  GZIPCompressorInputStream gzipCompressorInputStream = new GZIPCompressorInputStream(byteArrayInputStream);

  String encoded = Base64.encodeBytes(IOUtils.toByteArray(gzipCompressorInputStream), Base64.DONT_BREAK_LINES);
  GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(Base64.decodeWithoutUnzipping(encoded)));

  assertThat(IOUtils.toString(gzipInputStream), is(payload));
 }
}

代码示例来源:origin: mulesoft/mule

public HttpMessage(HttpExchange httpExchange) {
 this.body = IOUtils.toByteArray(httpExchange.getRequestBody());
 ImmutableMultimap.Builder<String, String> headersBuilder = ImmutableMultimap.builder();
 Set<String> headerNames = httpExchange.getRequestHeaders().keySet();
 headerNames.stream()
   .forEach(headerName -> headersBuilder.putAll(headerName, httpExchange.getRequestHeaders().get(headerName)));
 this.headers = headersBuilder.build();
 uri = httpExchange.getRequestURI().getPath();
 queryParams = queryToMap(httpExchange.getRequestURI().getQuery());
}

代码示例来源:origin: mulesoft/mule

@Override
public String getObject() throws Exception {
 String returnData = content;
 if (file != null) {
  try {
   returnData = getResourceAsString(file, getClass());
  } catch (IOException e) {
   throw new MuleRuntimeException(createStaticMessage("Failed to load test-data resource: " + file), e);
  }
 }
 return returnData;
}

代码示例来源:origin: org.mule.runtime/mule-module-builders

public PropertiesMuleConfigurationFactory(String muleAppConfiguration) {
 URL muleAppURL = ClassUtils.getResource(muleAppConfiguration, getClass());
 if (muleAppURL != null) {
  this.properties = new Properties();
  InputStream inputStream = null;
  try {
   inputStream = muleAppURL.openStream();
   this.properties.load(inputStream);
  } catch (IOException e) {
   logger.debug("Unable to read properties", e);
  } finally {
   closeQuietly(inputStream);
  }
 }
}

代码示例来源:origin: org.mule.runtime/mule-module-artifact

private <T> T createCustomInstance(String classLocation) {
 InputStream classStream = null;
 try {
  classStream = this.getClass().getResourceAsStream(classLocation);
  byte[] classBytes = IOUtils.toByteArray(classStream);
  classStream.close();
  Class clazz = this.defineClass(null, classBytes, 0, classBytes.length);
  return (T) clazz.newInstance();
 } catch (Exception e) {
  throw new RuntimeException("Can not create instance from resource: " + classLocation, e);
 } finally {
  closeQuietly(classStream);
 }
}

相关文章