info.aduna.io.IOUtil.readBytes()方法的使用及代码示例

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

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

IOUtil.readBytes介绍

[英]Reads all bytes from the specified file and returns them as a byte array.
[中]读取指定文件中的所有字节,并将其作为字节数组返回。

代码示例

代码示例来源:origin: info.aduna.commons/aduna-commons-io

public static boolean isZipStream(InputStream in)
  throws IOException
{
  in.mark(MAGIC_NUMBER.length);
  byte[] fileHeader = IOUtil.readBytes(in, MAGIC_NUMBER.length);
  in.reset();
  return Arrays.equals(MAGIC_NUMBER, fileHeader);
}

代码示例来源:origin: info.aduna.commons/aduna-commons-io

public static boolean isGZipStream(InputStream in)
    throws IOException
  {
    in.mark(MAGIC_NUMBER.length);
    byte[] fileHeader = IOUtil.readBytes(in, MAGIC_NUMBER.length);
    in.reset();
    return Arrays.equals(MAGIC_NUMBER, fileHeader);
  }
}

代码示例来源:origin: blazegraph/database

private void prepareForWire() throws Exception {
  
  if (file != null) {
    // set the data
    data = IOUtil.readBytes(file);
    
  } else if (stmts != null) {
    
    // set the data and content type (TRIG by default)
    format = RDFFormat.TRIG;
    data = serialize(stmts, format);
  }
  
}

代码示例来源:origin: info.aduna.commons/aduna-commons-io

/**
 * Reads at most <tt>maxBytes</tt> bytes from the supplied input stream and
 * returns them as a byte array.
 * 
 * @param in
 *        The InputStream supplying the bytes.
 * @param maxBytes
 *        The maximum number of bytes to read from the input stream.
 * @return A byte array of size <tt>maxBytes</tt> if the input stream can
 *         produce that amount of bytes, or a smaller byte array containing
 *         all available bytes from the stream otherwise.
 */
public static byte[] readBytes(InputStream in, int maxBytes)
  throws IOException
{
  byte[] result = new byte[maxBytes];
  int bytesRead = readBytes(in, result);
  if (bytesRead < maxBytes) {
    // Create smaller byte array
    byte[] tmp = new byte[bytesRead];
    System.arraycopy(result, 0, tmp, 0, bytesRead);
    result = tmp;
  }
  return result;
}

代码示例来源:origin: blazegraph/database

private void prepareForWire() throws Exception {
  
  if (file != null) {
    // set the data
    data = IOUtil.readBytes(file);
    
  } else if (is != null) {
    // set the data
    data = IOUtil.readBytes(is);
    
  } else if (reader != null) {
    // set the data
    data = IOUtil.readString(reader).getBytes();
    
  } else if (stmts != null) {
    
    // set the data and content type (TRIG by default)
    format = RDFFormat.TRIG;
    data = serialize(stmts, format);
  }
  
}

代码示例来源:origin: info.aduna.commons/aduna-commons-io

/**
 * Reads all bytes from the specified file and returns them as a byte array.
 * 
 * @param file
 *        The file to read.
 * @return A byte array containing all bytes from the specified file.
 * 
 * @throws IOException
 *         If an I/O error occurred while reading from the file.
 * @throws IllegalArgumentException
 *         If the file size exceeds the maximum array length (larger than
 *         {@link Integer#MAX_VALUE}.
 */
public static byte[] readBytes(File file)
  throws IOException
{
  long fileSize = file.length();
  if (fileSize > Integer.MAX_VALUE) {
    throw new IllegalArgumentException("File size exceeds maximum array length (" + fileSize + " > "
        + Integer.MAX_VALUE + ")");
  }
  FileInputStream in = new FileInputStream(file);
  try {
    return readBytes(in, (int)fileSize);
  }
  finally {
    in.close();
  }
}

代码示例来源:origin: net.fortytwo.extendo/extendo-brain

private void execute(final EmacsFunction f, final String text) throws IOException, InterruptedException, ExecutionException {
  Process p = functionExecutor.execute(f, text);
  if (null != p && 0 != p.exitValue()) {
    StringBuilder sb = new StringBuilder();
    sb.append("failed to execute emacs function ")
    .append(f.getName()).append(f.requiresArgument ? " with argument " + text : "")
    .append(" (exit code = ").append(p.exitValue()).append(").");
    byte[] in = IOUtil.readBytes(p.getInputStream());
    if (in.length > 0) {
      sb.append("\nInput: ");
      sb.append(new String(in));
    }
    byte[] out = IOUtil.readBytes(p.getErrorStream());
    if (out.length > 0) {
      sb.append("\nOutput: ");
      sb.append(new String(out));
    }
    throw new ExecutionException(sb.toString());
  }
}

代码示例来源:origin: synchrony/smsn

private void execute(final EmacsFunction f, final String text, final boolean doHandle)
    throws IOException, InterruptedException, ExecutionException {
  Process p = functionExecutor.execute(f, text);
  if (null == p) {
    return;
  }
  if (0 != p.exitValue()) {
    StringBuilder sb = new StringBuilder();
    sb.append("failed to execute emacs function ")
        .append(f.getName()).append(f.requiresArgument ? " with argument " + text : "")
        .append(" (exit code = ").append(p.exitValue()).append(").");
    byte[] in = IOUtil.readBytes(p.getInputStream());
    if (in.length > 0) {
      sb.append("\nInput: ");
      sb.append(new String(in));
    }
    byte[] out = IOUtil.readBytes(p.getErrorStream());
    if (out.length > 0) {
      sb.append("\nOutput: ");
      sb.append(new String(out));
    }
    throw new ExecutionException(sb.toString());
  } else if (doHandle) {
    try {
      resultHandler.handle(p.getInputStream());
    } catch (Throwable t) {
      logger.log(Level.SEVERE, "failed to handle Brain-mode client result", t);
    }
  }
}

代码示例来源:origin: blazegraph/database

final byte[] data = IOUtil.readBytes(file);

代码示例来源:origin: synchrony/smsn

String s0;
try {
  s0 = new String(IOUtil.readBytes(result)).trim();
} catch (IOException e) {
  logger.log(Level.SEVERE, "error reading Brain-mode response", e);

代码示例来源:origin: org.openrdf.sesame/sesame-rio-binary

byte[] magicNumber = IOUtil.readBytes(in, MAGIC_NUMBER.length);
if (!Arrays.equals(magicNumber, MAGIC_NUMBER)) {
  reportFatalError("File does not contain a binary RDF document");

相关文章