コード例 #1
0
 /** 从sd卡中的文件读取到byte[]. */
 public void testWriteByteArrayToSD() {
   byte[] fileByte =
       SaFileUtils.getByteArrayFromSD(
           "mnt/sdcard/download/com.martin.ionichina/images/ee6d78cc5c46411c0b6f7ff8ba1318ca.png");
   SaFileUtils.writeByteArrayToSD(
       "mnt/sdcard/download/com.martin.ionichina/images/tempByte.png", fileByte, true);
 }
コード例 #2
0
 /**
  * 通过文件的本地地址从SD卡读取图片.<br>
  * 图片质量<br>
  * 指定大小
  */
 public void testGetLocalTypeBitmapFromSD() {
   SaFileUtils.getBitmapFromSD(
       new File(
           "mnt/sdcard/download/com.martin.ionichina/images/ee6d78cc5c46411c0b6f7ff8ba1318ca.png"),
       SaImageUtils.CUTIMG,
       20,
       20);
 }
コード例 #3
0
 /**
  * 获取文件后缀,本地.
  *
  * @throws IOException
  */
 public void testGetMIMEFromUrl() throws IOException {
   String url = "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg";
   URL mUrl = new URL(url);
   HttpURLConnection mHttpURLConnection = (HttpURLConnection) mUrl.openConnection();
   mHttpURLConnection.setConnectTimeout(5 * 1000);
   mHttpURLConnection.setRequestMethod("GET");
   mHttpURLConnection.setRequestProperty(
       "Accept",
       "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
   mHttpURLConnection.setRequestProperty("Accept-Language", "zh-CN");
   mHttpURLConnection.setRequestProperty("Referer", url);
   mHttpURLConnection.setRequestProperty("Charset", "UTF-8");
   mHttpURLConnection.setRequestProperty("User-Agent", "");
   mHttpURLConnection.setRequestProperty("Connection", "Keep-Alive");
   mHttpURLConnection.connect();
   SaFileUtils.getMIMEFromUrl(url, mHttpURLConnection);
 }
コード例 #4
0
  /** 打开Asset中的文件 */
  public void testLocalOpenAssetFile() {
    String url = "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg";
    // HttpGet对象
    HttpGet httpGet = new HttpGet(url);
    try {
      // 取得HttpClient对象
      HttpClient httpClient = new DefaultHttpClient();
      // 请求HttpClient,取得HttpResponse
      HttpResponse httpResponse = httpClient.execute(httpGet);
      // 请求成功
      if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        SaFileUtils.getMIMEFromUrl(url, httpResponse);
      } else {

      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #5
0
  /**
   * 获取真实文件名(xx.后缀),通过网络获取.
   *
   * @throws IOException
   */
  @SuppressWarnings("deprecation")
  public void testHttpResponseGetRealFileName() {
    SaLogUtils.d(TAG, "获取真实文件名(xx.后缀),通过网络获取.");
    String url = "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg";
    // HttpGet对象
    HttpGet httpGet = new HttpGet(url);
    try {
      // 取得HttpClient对象
      HttpClient httpClient = new DefaultHttpClient();
      // 请求HttpClient,取得HttpResponse
      HttpResponse httpResponse = httpClient.execute(httpGet);
      // 请求成功
      if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        SaFileUtils.getRealFileName(httpResponse);
      } else {

      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #6
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   SaFileUtils.initFileDir(getActivity());
   SaLogUtils.d(TAG, "单元测试开始.....setUp");
 }
コード例 #7
0
 /** 打开Asset中的文件 */
 public void testOpenAssetFile() {
   SaFileUtils.openAssetFile(getActivity(), "test.txt");
 }
コード例 #8
0
 /** 读取Assets目录的文件内容. */
 public void testReadRawByName() {
   SaFileUtils.readRawByName(getActivity(), R.raw.raw_test, "UTF-8");
 }
コード例 #9
0
 /** 读取Assets目录的文件内容. */
 public void testReadAssetsByName() {
   SaFileUtils.readAssetsByName(getActivity(), "test.txt", "UTF-8");
 }
コード例 #10
0
 /** 获取文件名,通过网络获取. */
 public void testGetContentLengthFromUrl() {
   SaFileUtils.getContentLengthFromUrl(
       "http://leiphone.qiniudn.com/uploads/new/article/600_600/201412/54a3953e913f7.jpg");
 }
コード例 #11
0
 /** 获取src中的图片资源. */
 public void testGetBitmapFromSrc() {
   SaFileUtils.getBitmapFromSrc("/com/martin/utils/image/ic_launcher.png");
 }
コード例 #12
0
 /** 将图片的byte[]写入本地文件. */
 public void testGetBitmapFromByte() {
   byte[] fileByte =
       SaFileUtils.getByteArrayFromSD(
           "mnt/sdcard/download/com.martin.ionichina/images/ee6d78cc5c46411c0b6f7ff8ba1318ca.png");
   SaFileUtils.getBitmapFromByte(fileByte, "temp2.png", SaImageUtils.ORIGINALIMG, 20, 20);
 }
コード例 #13
0
 /** 从sd卡中的文件读取到byte[]. */
 public void testGetByteArrayFromSD() {
   SaFileUtils.getByteArrayFromSD(
       "mnt/sdcard/download/com.martin.ionichina/images/ee6d78cc5c46411c0b6f7ff8ba1318ca.png");
 }
コード例 #14
0
 /** 获取文件名(不含后缀).MD5加密之后的 */
 public void testGetMD5CacheFileNameFromUrl() {
   String url = "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg";
   SaFileUtils.getCacheFileNameFromUrl(url);
 }
コード例 #15
0
 /** 获取文件名,通过网络获取. */
 public void testGetRealFileNameFromUrl() {
   SaFileUtils.getRealFileNameFromUrl(
       "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg");
 }
コード例 #16
0
 /**
  * 通过文件的网络地址从SD卡中读取图片,如果SD中没有则自动下载并保存. <br>
  * ImageUtil.ORIGINALIMG-->原图不处理<br>
  * ImageUtil.SCALEIMG-->缩放 <br>
  * ImageUtil.CUTIMG-->裁剪
  */
 public void testGetBitmapFromSD() {
   SaFileUtils.getBitmapFromSD("http://huaban.com/img/pink_pic.png", SaImageUtils.CUTIMG, 20, 20);
 }
コード例 #17
0
 /** SD卡是否能用. */
 public void testIsCanUseSD() {
   SaFileUtils.isCanUseSD();
 }
コード例 #18
0
 /** 计算sdcard上的剩余空间. */
 public void testFreeSpaceOnSD() {
   SaFileUtils.freeSpaceOnSD();
 }
コード例 #19
0
 /** 根据URL从互连网获取图片. */
 public void testGetBitmapFromURL() {
   SaFileUtils.getBitmapFromURL(
       "http://huaban.com/img/pink_pic.png", SaImageUtils.ORIGINALIMG, 20, 20);
 }
コード例 #20
0
 /** 删除所有缓存文件. */
 public void testClearDownloadFile() {
   SaFileUtils.clearDownloadFile();
 }
コード例 #21
0
 /** 获取Asset中的图片资源.Bitmap */
 public void testGetBitmapFromAsset() {
   SaFileUtils.getBitmapFromAsset(getActivity(), "ic_launcher.png");
 }
コード例 #22
0
 /** 获取Asset中的图片资源.Drawable */
 public void testDownloadFile() {
   SaFileUtils.downloadFile(
       "http://leiphone.qiniudn.com/uploads/new/article/600_600/201412/54a3953e913f7.jpg");
 }