作者:书友48169582 | 来源:互联网 | 2023-10-11 10:10
本文整理了Java中org.openimaj.io.IOUtils.readable()
方法的一些代码示例,展示了IOUtils.readable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.readable()
方法的具体详情如下:
包路径:org.openimaj.io.IOUtils
类名称:IOUtils
方法名:readable
IOUtils.readable介绍
[英]Check whether an InputStream can be read by an instantiated class based on it's binary and ascii headers. Buffered so the stream can be reset after the check.
[中]检查一个实例化的类是否可以根据其二进制和ascii头读取InputStream。缓冲,以便检查后可以重置流。
代码示例
代码示例来源:origin: openimaj/openimaj
/**
* Check whether an input stream starts with a header string. Calls the
* byte[] version of this function
*
* @see IOUtils#isBinary(BufferedInputStream, byte[])
*
* @param bis
* the input stream
* @param header
* the header
* @return whether the stream starts with the string
* @throws IOException
* error reading stream
*/
public static boolean readable(BufferedInputStream bis, String header) throws IOException {
return readable(bis, header.getBytes());
}
代码示例来源:origin: openimaj/openimaj
/**
* Check whether a file is readable by checking it's first bytes contains
* the header. Converts the header to a byte[] and calls the byte[] version
* of this method
*
* @see IOUtils#readable(File, byte[])
*
* @param f
* the file to check
* @param header
* the header to check with
* @return does this file contain this header
* @throws IOException
* error reading file
*/
public static boolean readable(File f, String header) throws IOException {
return readable(f, header.getBytes());
}
代码示例来源:origin: openimaj/openimaj
/**
* Check whether an InputStream can be read by an instantiated class based
* on it's binary and ascii headers. Buffered so the stream can be reset
* after the check.
*
* @param
* instance type expected
* @param bis
* the stream
* @param cls
* the class to instantiate and check
* @return can an object be read from this stream of the class type
* @throws IOException
* error reading stream
*/
public static boolean readable(BufferedInputStream bis, Class cls) throws IOException
{
final InternalReadable obj = newInstance(cls);
return (obj instanceof ReadableBinary && readable(bis, ((ReadableBinary) obj).binaryHeader())) ||
(obj instanceof ReadableASCII && readable(bis, ((ReadableASCII) obj).asciiHeader()));
}
代码示例来源:origin: openimaj/openimaj
/**
* Check whether a given file is readable by a given Writeable class.
* Instantiates the class to get it's binary and ascii header which is then
* passed to the byte[] version of this method
*
* @see Readable#asciiHeader()
*
* @param
* instance type expected
* @param f
* the file to check
* @param cls
* the class to instantiate the Readable object
* @return is file readable by a given class
* @throws IOException
* error reading file
*/
public static boolean readable(File f, Class cls) throws IOException {
final InternalReadable obj = newInstance(cls);
return (obj instanceof ReadableBinary && readable(f, ((ReadableBinary) obj).binaryHeader())) ||
(obj instanceof ReadableASCII && readable(f, ((ReadableASCII) obj).asciiHeader()));
}
代码示例来源:origin: openimaj/openimaj
/**
* Guess the type of the clusters based on the file header
*
* @param oldout
* @return guessed type
*/
public static ClusterTypeOp sniffClusterType(BufferedInputStream oldout) {
for (final ClusterType c : ClusterType.values()) {
for (final Precision p : Precision.values()) {
final ClusterTypeOp opts = (ClusterTypeOp) c.getOptions();
opts.precision = p;
try {
if (IOUtils.readable(oldout, opts.getClusterClass())) {
return opts;
}
} catch (final Exception e) {
e.printStackTrace();
}
}
}
return null;
}
}
代码示例来源:origin: openimaj/openimaj
/**
* Guess the type of the clusters based on the file header
*
* @param oldout
* @return guessed type
*/
public static ClusterTypeOp sniffClusterType(File oldout) {
for (final ClusterType c : ClusterType.values()) {
for (final Precision p : Precision.values()) {
final ClusterTypeOp opts = (ClusterTypeOp) c.getOptions();
opts.precision = p;
try {
if (IOUtils.readable(oldout, opts.getClusterClass()))
return opts;
} catch (final Exception e) {
}
}
}
return null;
}