@Override public Object fromBody(TypedInput typedInput, Type type) throws ConversionException { try { return StreamUtils.readInputStream(typedInput.in(), "utf-8"); } catch (IOException exception) { exception.printStackTrace(); } return null; }
@Override public void run() { try { // TODO Auto-generated method stub // 在线程内存访问网络 HttpURLConnection // 拿到一个流 URL urlObj = new URL(url); // 生成Bitmap HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); if (200 == conn.getResponseCode()) { InputStream input = conn.getInputStream(); // 使用工具快速生成bitmap对象 byte[] bytes = StreamUtils.readInputStream(input); // Bitmap bitmap = BitmapFactory.decodeStream(input); Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); if (bitmap != null) { Message msg = new Message(); msg.what = 200; HashMap<String, Object> data = new HashMap<String, Object>(); data.put("imagview", imageView); // 停止出现图片错乱问题 data.put("bitmap", bitmap); msg.obj = data; handler.sendMessage(msg); // -->handlemesssage(); // Log.i("wzx", "imageview"); // Log.i("wzx", "gridview"); // Log.i("wzx", "listview"); // 保存到集合 cache.put(url, bitmap); // 保存到文件目录 writeToLocal(url, bitmap); } return; } } catch (Exception e) { // TODO: handle exception } Message msg = new Message(); msg.what = 404; handler.sendMessage(msg); }