java Android 上的 Apache Commons IO
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17359163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache Commons IO on Android
提问by VansFannel
I'm developing an Android application that uses Apache Commons IO, commons-io-2.4-bin.tar.gz.
我正在开发一个使用Apache Commons IO的 Android 应用程序,commons-io-2.4-bin.tar.gz。
And I get some errors, one of them:
我得到了一些错误,其中之一:
Could not find method java.lang.String.getBytes, referenced from method org.apache.commons.io.IOUtils.toInputStream
I think I don't have to worry about it, isn't it?
我想我不必担心,不是吗?
Is there another specific Android library that I can use instead of Apache Commons IO?
我可以使用另一个特定的 Android 库来代替 Apache Commons IO 吗?
I'm using it here:
我在这里使用它:
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.ResponseErrorHandler;
import android.util.Log;
public class CustomResponseErrorHandler implements ResponseErrorHandler
{
private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler();
@Override
public void handleError(ClientHttpResponse response) throws IOException
{
String theString = IOUtils.toString(response.getBody());
Log.v("Error Handler", theString);
CustomException exception = new CustomException();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("code", response.getStatusCode().toString());
properties.put("body", theString);
properties.put("header", response.getHeaders());
exception.setProperties(properties);
throw exception;
}
@Override
public boolean hasError(ClientHttpResponse response) throws IOException
{
return errorHandler.hasError(response);
}
}
On this line:
在这一行:
String theString = IOUtils.toString(response.getBody());
采纳答案by Jasper
Guavamight be a good replacement for you. Their wikiclaims they're fully compatible with Android:
番石榴可能是你的一个很好的替代品。他们的 wiki声称他们与 Android 完全兼容:
Guava 11.0.2 and earlier are fully compatible with Android, but more recent Android versions may be required for the latest Guava releases. In particular, NavigableSet and other extensions added in Java 6 (used by Guava 12 and above) were added in Android API version 9, corresponding with Gingerbread.
(Android programmers concerned with Guava's large JAR size are advised to use ProGuard to get only the parts of Guava they need. Guava is one of the most common dependencies for Android applications.)
Guava 11.0.2 及更早版本与 Android 完全兼容,但最新的 Guava 版本可能需要更新的 Android 版本。尤其是在Android API 9 版本中加入了Java 6 中添加的NavigableSet 等扩展(Guava 12 及以上版本使用),对应Gingerbread。
(建议担心 Guava 较大 JAR 大小的 Android 程序员使用 ProGuard 来仅获取他们需要的 Guava 部分。Guava 是 Android 应用程序最常见的依赖项之一。)
For the Guava equivalent of IOUtils.toString()
check the following question: Guava equivalent for IOUtils.toString(InputStream)
对于相当于IOUtils.toString()
检查以下问题的番石榴:番石榴相当于 IOUtils.toString(InputStream)