本文整理了Java中org.robolectric.util.Util.readBytes()
方法的一些代码示例,展示了Util.readBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.readBytes()
方法的具体详情如下:
包路径:org.robolectric.util.Util
类名称:Util
方法名:readBytes
[英]This method consumes an input stream and returns its content.
[中]此方法使用输入流并返回其内容。
代码示例来源:origin: robolectric/robolectric
protected byte[] getByteCode(String className) throws ClassNotFoundException {
String classFilename = className.replace('.', '/') + ".class";
try (InputStream classBytesStream = getClassBytesAsStreamPreferringLocalUrls(classFilename)) {
if (classBytesStream == null) {
throw new ClassNotFoundException(className);
}
return Util.readBytes(classBytesStream);
} catch (IOException e) {
throw new ClassNotFoundException("couldn't load " + className, e);
}
}
代码示例来源:origin: robolectric/robolectric
public static byte[] getBytes(Path path) throws IOException {
return Util.readBytes(getInputStream(path));
}
代码示例来源:origin: robolectric/robolectric
private static byte[] getClassBytes(String className, JarFile jarFile)
throws ClassNotFoundException {
String classFilename = className.replace('.', '/') + ".class";
ZipEntry entry = jarFile.getEntry(classFilename);
try {
InputStream inputStream;
if (entry == null) {
inputStream = JarInstrumentor.class.getClassLoader().getResourceAsStream(classFilename);
} else {
inputStream = jarFile.getInputStream(entry);
}
if (inputStream == null) {
throw new ClassNotFoundException("Couldn't find " + className.replace('/', '.'));
}
return Util.readBytes(inputStream);
} catch (IOException e) {
throw new ClassNotFoundException("Couldn't load " + className.replace('/', '.'), e);
}
}
代码示例来源:origin: robolectric/robolectric
@Nonnull
private List<Path> getDirectoriesFromProperty(String property) {
if (property == null) {
return Collections.emptyList();
}
List<String> dirs;
if (property.startsWith("@")) {
String filename = property.substring(1);
try {
dirs = Arrays.asList(
new String(Util.readBytes(new FileInputStream(filename)), UTF_8).split("\\n"));
} catch (IOException e) {
throw new RuntimeException("Cannot read file " + filename);
}
} else {
dirs = Arrays.asList(property.split(File.pathSeparator));
}
List<Path> files = new ArrayList<>();
for (String dir : dirs) {
files.add(Fs.fromUrl(dir));
}
return files;
}
}
代码示例来源:origin: robolectric/robolectric
private void interceptResponseContent(HttpResponse response) {
HttpEntity entity = response.getEntity();
if (entity instanceof HttpEntityWrapper) {
HttpEntityWrapper entityWrapper = (HttpEntityWrapper) entity;
try {
Field wrappedEntity = HttpEntityWrapper.class.getDeclaredField("wrappedEntity");
wrappedEntity.setAccessible(true);
entity = (HttpEntity) wrappedEntity.get(entityWrapper);
} catch (Exception e) {
// fail to record
}
}
if (entity instanceof BasicHttpEntity) {
BasicHttpEntity basicEntity = (BasicHttpEntity) entity;
try {
Field contentField = BasicHttpEntity.class.getDeclaredField("content");
contentField.setAccessible(true);
InputStream content = (InputStream) contentField.get(basicEntity);
byte[] buffer = Util.readBytes(content);
FakeHttp.getFakeHttpLayer().addHttpResponseContent(buffer);
contentField.set(basicEntity, new ByteArrayInputStream(buffer));
} catch (Exception e) {
// fail to record
}
}
}
}
代码示例来源:origin: bumptech/glide
@Test
public void testHandlesParsingOrientationWithMinimalExifSegment() throws IOException {
byte[] data =
Util.readBytes(TestResourceUtil.openResource(getClass(), "short_exif_sample.jpg"));
runTest(data, new ParserTestCase() {
@Override
public void run(DefaultImageHeaderParser parser, InputStream is, ArrayPool byteArrayPool)
throws IOException {
assertEquals(-1, parser.getOrientation(is, byteArrayPool));
}
@Override
public void run(DefaultImageHeaderParser parser, ByteBuffer byteBuffer,
ArrayPool byteArrayPool) throws IOException {
assertEquals(-1, parser.getOrientation(byteBuffer, byteArrayPool));
}
});
}
代码示例来源:origin: org.robolectric/robolectric
@Nonnull
private List<FsFile> getDirectoriesFromProperty(String property) {
if (property == null) {
return Collections.emptyList();
}
List<String> dirs;
if (property.startsWith("@")) {
String filename = property.substring(1);
try {
dirs = Arrays.asList(
new String(Util.readBytes(new FileInputStream(filename)), UTF_8).split("\\n"));
} catch (IOException e) {
throw new RuntimeException("Cannot read file " + filename);
}
} else {
dirs = Arrays.asList(property.split(File.pathSeparator));
}
List<FsFile> files = new ArrayList<>();
for (String dir : dirs) {
files.add(Fs.fileFromPath(dir));
}
return files;
}
}
代码示例来源:origin: org.robolectric/robolectric-resources
@Override
public byte[] getBytes() throws IOException {
return Util.readBytes(new FileInputStream(file));
}
代码示例来源:origin: org.robolectric/resources
@Override
public byte[] getBytes() throws IOException {
return Util.readBytes(new FileInputStream(file));
}
代码示例来源:origin: org.robolectric/resources
@Override public byte[] getBytes() throws IOException {
return Util.readBytes(jarFile.getInputStream(jarEntryMap.get(path)));
}
代码示例来源:origin: org.robolectric/robolectric-resources
@Override public byte[] getBytes() throws IOException {
return Util.readBytes(jarFile.getInputStream(jarEntryMap.get(path)));
}
代码示例来源:origin: org.robolectric/robolectric-sandbox
protected byte[] getByteCode(String className) throws ClassNotFoundException {
String classFilename = className.replace('.', '/') + ".class";
try (InputStream classBytesStream = getClassBytesAsStreamPreferringLocalUrls(classFilename)) {
if (classBytesStream == null) throw new ClassNotFoundException(className);
return Util.readBytes(classBytesStream);
} catch (IOException e) {
throw new ClassNotFoundException("couldn't load " + className, e);
}
}
内容来源于网络,如有侵权,请联系作者删除!