org.javalite.common.Util.bytes()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(184)

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

Util.bytes介绍

[英]Reads contents of the input stream fully and returns it as byte array.
[中]完全读取输入流的内容,并将其作为字节数组返回。

代码示例

代码示例来源:origin: javalite/activejdbc

/**
 * Reads file into a byte array.
 *
 * @param file file to read.
 * @return content of file.
 * @throws java.io.IOException
 */
public static byte[] read(File file) throws IOException {
  FileInputStream is = new FileInputStream(file);
  try {
    return bytes(is);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: javalite/activejdbc

/**
 * Reads contents of resource fully into a byte array.
 *
 * @param resourceName resource name.
 * @return entire contents of resource as byte array.
 */
public static byte[] readResourceBytes(String resourceName) {
  InputStream is = Util.class.getResourceAsStream(resourceName);
  try {
    return bytes(is);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: javalite/activejdbc

/**
 * Converts <code>java.sql.Blob</code> to bytes array.
 *
 * @param blob Blob to be converted
 * @return blob converted to byte array
 */
public static byte[] toBytes(Blob blob) {
  InputStream is = null;
  try {
    is = blob.getBinaryStream();
    return bytes(is);
  } catch (Exception e) {
    throw new ConversionException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: javalite/activeweb

/**
 * Constructor  to be used in tests, field name and file name are set to File name.
 * Content type set to "text/plain".
 *
 * @param file file to send.
 * @throws IOException
 */
public FileItem(File file) throws IOException {
  super(file.getName(), file.getName(), true, "text/plain", Util.bytes(new FileInputStream(file)));
}

代码示例来源:origin: javalite/activeweb

/**
 * Reads entire request data as byte array. Do not use for large data sets to avoid
 * memory issues.
 *
 * @return data sent by client as string.
 * @throws IOException
 */
protected byte[] getRequestBytes() throws IOException {
  return Util.bytes(RequestContext.getHttpRequest().getInputStream());
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Reads file into a byte array.
 *
 * @param file file to read.
 * @return content of file.
 * @throws java.io.IOException
 */
public static byte[] read(File file) throws IOException {
  FileInputStream is = new FileInputStream(file);
  try {
    return bytes(is);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Reads contents of resource fully into a byte array.
 *
 * @param resourceName resource name.
 * @return entire contents of resource as byte array.
 */
public static byte[] readResourceBytes(String resourceName) {
  InputStream is = Util.class.getResourceAsStream(resourceName);
  try {
    return bytes(is);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Reads file into a byte array.
 *
 * @param file file to read.
 * @return content of file.
 * @throws java.io.IOException
 */
public static byte[] read(File file) throws IOException {
  FileInputStream is = new FileInputStream(file);
  try {
    return bytes(is);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Reads contents of resource fully into a byte array.
 *
 * @param resourceName resource name.
 * @return entire contents of resource as byte array.
 */
public static byte[] readResourceBytes(String resourceName) {
  InputStream is = Util.class.getResourceAsStream(resourceName);
  try {
    return bytes(is);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: javalite/activeweb

/**
 * Reads contents of a file into a byte array at once.
 *
 * @return contents of a file as byte array.
 */
public byte[] getBytes() {
  try {
    return Util.bytes(fileItemStream.openStream());
  } catch (Exception e) {
    throw new ControllerException(e);
  }
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Converts <code>java.sql.Blob</code> to bytes array.
 *
 * @param blob Blob to be converted
 * @return blob converted to byte array
 */
public static byte[] toBytes(Blob blob) {
  InputStream is = null;
  try {
    is = blob.getBinaryStream();
    return bytes(is);
  } catch (Exception e) {
    throw new ConversionException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Converts <code>java.sql.Blob</code> to bytes array.
 *
 * @param blob Blob to be converted
 * @return blob converted to byte array
 */
public static byte[] toBytes(Blob blob) {
  InputStream is = null;
  try {
    is = blob.getBinaryStream();
    return bytes(is);
  } catch (Exception e) {
    throw new ConversionException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: javalite/activeweb

@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
  try{
    if (name.startsWith("org.javalite.activeweb")) {
      return loadByParent(name);
    }
    if(name.endsWith("Controller") || name.contains("Controller$")
        || name.equals(Configuration.getRouteConfigClassName())){
      String pathToClassFile = name.replace('.', '/') + ".class";
      byte[] classBytes = bytes(getResourceAsStream(pathToClassFile));
      Class<?> daClass = defineClass(name, classBytes, 0, classBytes.length);
      LOGGER.debug("Loaded class: " + name);
      return daClass;
    }else{
      return loadByParent(name);
    }
  }
  catch(Exception e){
    LOGGER.debug("Failed to dynamically load class: " + name + ". Loading by parent class loader.");
    return loadByParent(name);
  }
}

相关文章