jodd.io.FileUtil.readBytes()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(522)

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

FileUtil.readBytes介绍

暂无

代码示例

代码示例来源:origin: redisson/redisson

/**
   * Checks the start of the file for ASCII control characters
   */
  public static boolean isBinary(final File file) throws IOException {
    byte[] bytes = readBytes(file, 128);

    for (byte b : bytes) {
      if (b < 32) {
        return true;
      }
    }

    return false;
  }
}

代码示例来源:origin: redisson/redisson

public static byte[] readBytes(File file) throws IOException {
  return readBytes(file, -1);
}
public static byte[] readBytes(File file, int fixedLength) throws IOException {

代码示例来源:origin: oblac/jodd

/**
 * @see #readBytes(File, int)
 */
public static byte[] readBytes(final File file) throws IOException {
  return readBytes(file, NEGATIVE_ONE);
}

代码示例来源:origin: oblac/jodd

/**
 * Returns files content from disk file.
 * If error occurs, it returns <code>null</code>
 */
@Override
public byte[] getFileContent() throws IOException {
  return FileUtil.readBytes(file);
}

代码示例来源:origin: oblac/jodd

/**
 * Returns the content of file upload item.
 */
@Override
public byte[] getFileContent() throws IOException {
  if (data != null) {
    return data;
  }
  if (tempFile != null) {
    return FileUtil.readBytes(tempFile);
  }
  return null;
}

代码示例来源:origin: oblac/jodd

/**
 * Checks the start of the file for ASCII control characters
 *
 * @param file {@link File}
 * @return true if the the start of the {@link File} is ASCII control characters.
 */
public static boolean isBinary(final File file) throws IOException {
  byte[] bytes = readBytes(file, 128);
  for (byte b : bytes) {
    if (b < 32 && b != 9 && b != 10 && b != 13) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: redisson/redisson

public byte[] toBytes() {
  StreamUtil.close(zos);
  if (targetZipFile != null) {
    try {
      return FileUtil.readBytes(targetZipFile);
    }
    catch (IOException ignore) {
      return null;
    }
  }
  return targetBaos.toByteArray();
}

代码示例来源:origin: redisson/redisson

public static byte[] readBytes(String file) throws IOException {
  return readBytes(file(file));
}

代码示例来源:origin: oblac/jodd

@Override
public byte[] getBytes() {
  try {
    return FileUtil.readBytes(file);
  } catch (IOException ioex) {
    throw new HttpException(ioex);
  }
}

代码示例来源:origin: oblac/jodd

/**
 * @see #readBytes(File)
 */
public static byte[] readBytes(final String file) throws IOException {
  return readBytes(file(file));
}

代码示例来源:origin: oblac/jodd

public byte[] toBytes() {
  StreamUtil.close(zos);
  if (targetZipFile != null) {
    try {
      return FileUtil.readBytes(targetZipFile);
    }
    catch (IOException ignore) {
      return null;
    }
  }
  return targetBaos.toByteArray();
}

代码示例来源:origin: redisson/redisson

/**
 * Returns cached file bytes.
 */
public byte[] getFileBytes(File file) throws IOException {
  byte[] bytes = cache.get(file);
  if (bytes != null) {
    return bytes;
  }
  // add file
  bytes = FileUtil.readBytes(file);
  if ((maxFileSize != 0) && (file.length() > maxFileSize)) {
    // don't cache files that size exceed max allowed file size
    return bytes;
  }
  usedSize += bytes.length;
  // put file into cache
  // if used size > total, purge() will be invoked
  cache.put(file, bytes);
  return bytes;
}

代码示例来源:origin: oblac/jodd

/**
 * Returns cached file bytes. If file is not cached it will be
 * read and put in the cache (if all the rules are satisfied).
 */
public byte[] getFileBytes(final File file) throws IOException {
  byte[] bytes = cache.get(file);
  if (bytes != null) {
    return bytes;
  }
  // add file
  bytes = FileUtil.readBytes(file);
  if ((maxFileSize != 0) && (file.length() > maxFileSize)) {
    // don't cache files that size exceed max allowed file size
    return bytes;
  }
  usedSize += bytes.length;
  // put file into cache
  // if used size > total, purge() will be invoked
  cache.put(file, bytes);
  return bytes;
}

代码示例来源:origin: redisson/redisson

return FileUtil.readBytes((File) value);
} catch (IOException ioex) {
  throw new TypeConversionException(value, ioex);

代码示例来源:origin: oblac/jodd

return FileUtil.readBytes((File) value);
} catch (IOException ioex) {
  throw new TypeConversionException(value, ioex);

代码示例来源:origin: oblac/jodd

@Override
  public boolean serialize(final JsonContext jsonContext, final File file) {
    switch (serializationType) {
      case PATH:
        jsonContext.writeString(file.getAbsolutePath());
        break;
      case NAME:
        jsonContext.writeString(file.getName());
        break;
      case CONTENT: {
          byte[] bytes;

          try {
            bytes = FileUtil.readBytes(file);
          }
          catch (IOException e) {
            throw new JsonException("Unable to read files content", e);
          }

          String encoded = Base64.encodeToString(bytes);

          jsonContext.writeString(encoded);
        }
        break;
      default:
        throw new JsonException("Invalid type");
    }
    return true;
  }
}

代码示例来源:origin: oblac/jodd

@Test
void testGzip() throws IOException {
  ZipUtil.gzip(new File(dataRoot, "sb.data"));
  File gzipFile = new File(dataRoot, "sb.data.gz");
  assertTrue(gzipFile.exists());
  FileUtil.move(gzipFile, new File(dataRoot, "sb2.data.gz"));
  ZipUtil.ungzip(new File(dataRoot, "sb2.data.gz"));
  File data = new File(dataRoot, "sb2.data");
  assertTrue(data.exists());
  byte[] data2Bytes = FileUtil.readBytes(data);
  byte[] data1Bytes = FileUtil.readBytes(new File(dataRoot, "sb.data"));
  assertTrue(Arrays.equals(data1Bytes, data2Bytes));
  // cleanup
  FileUtil.delete(new File(dataRoot, "sb2.data"));
  FileUtil.delete(new File(dataRoot, "sb2.data.gz"));
}

代码示例来源:origin: oblac/jodd

@Test
void testNoContentLength() throws IOException {
  URL data = RawTest.class.getResource("3-response.txt");
  byte[] fileContent = FileUtil.readBytes(data.getFile());
  HttpResponse httpResponse = HttpResponse.readFrom(new ByteArrayInputStream(fileContent));
  assertEquals("Body!", httpResponse.bodyText());
}

代码示例来源:origin: oblac/jodd

@Test
void testBytes() {
  try {
    File file = new File(dataRoot + "/file/a.txt");
    byte[] bytes = FileUtil.readBytes(dataRoot + "/file/a.txt");
    assertEquals(file.length(), bytes.length);
    String content = new String(bytes);
    content = StringUtil.remove(content, '\r');
    assertEquals("test file\n", content);
  } catch (IOException ioex) {
    fail(ioex.toString());
  }
}

代码示例来源:origin: oblac/jodd

@Test
void testNoBody() throws IOException {
  /*HttpResponse httpResponse = HttpRequest.get("http://maps.googleapis.com/maps/api/geocode/json")
          .query("address", "14621")
          .query("sensor", "false")
          .send();
   */
  URL data = RawTest.class.getResource("2-response.txt");
  byte[] fileContent = FileUtil.readBytes(data.getFile());
  HttpResponse httpResponse = HttpResponse.readFrom(new ByteArrayInputStream(fileContent));
  try {
    httpResponse.bodyText();
  } catch (Exception ex) {
    fail(ex.toString());
  }
  assertEquals("", httpResponse.bodyText());
}

相关文章