package com.talent.allshare.util;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.cybergarage.util.CommonLog;
import org.cybergarage.util.LogFactory;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
public class FileHelper {
private static final CommonLog log = LogFactory.createLog();
private static final int FILE_BUFFER_SIZE = 51200;
public static boolean fileIsExist(String filePath) {
if (filePath == null || filePath.length() < 1) {
log.e("param invalid, filePath: " + filePath);
return false;
}
File f = new File(filePath);
if (!f.exists()) {
return false;
}
return true;
}
public static InputStream readFile(String filePath) {
if (null == filePath) {
log.e("Invalid param. filePath: " + filePath);
return null;
}
InputStream is = null;
try {
if (fileIsExist(filePath)) {
File f = new File(filePath);
is = new FileInputStream(f);
} else {
return null;
}
} catch (Exception ex) {
log.e("Exception, ex: " + ex.toString());
return null;
}
return is;
}
public static boolean createDirectory(String filePath){
if (null == filePath) {
return false;
}
File file = new File(filePath);
if (file.exists()){
return true;
}
file.mkdirs();
return true;
}
public static boolean deleteDirectory(String filePath) {
if (null == filePath) {
log.e("Invalid param. filePath: " + filePath);
return false;
}
File file = new File(filePath);
if (file == null || !file.exists()) {
return false;
}
if (file.isDirectory()) {
File[] list = file.listFiles();
for (int i = 0; i < list.length; i++) {
log.d("delete filePath: " + list[i].getAbsolutePath());
if (list[i].isDirectory()) {
deleteDirectory(list[i].getAbsolutePath());
} else {
list[i].delete();
}
}
}
log.d("delete filePath: " + file.getAbsolutePath());
file.delete();
return true;
}
public static boolean writeFile(String filePath, InputStream inputStream) {
if (null == filePath || filePath.length() < 1) {
log.e("Invalid param. filePath: " + filePath);
return false;
}
try {
File file = new File(filePath);
if (file.exists()) {
deleteDirectory(filePath);
}
String pth = filePath.substring(0, filePath.lastIndexOf("/"));
boolean ret = createDirectory(pth);
if (!ret){
log.e("createDirectory fail path = " + pth);
return false;
}
boolean ret1 = file.createNewFile();
if (!ret){
log.e("createNewFile fail filePath = " + filePath);
return false;
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int c = inputStream.read(buf);
while(-1 != c) {
fileOutputStream.write(buf, 0, c);
c = inputStream.read(buf);
}
fileOutputStream.flush();
fileOutputStream.close();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean writeFile(String filePath, String fileContent) {
return writeFile(filePath, fileContent, false);
}
public static boolean writeFile(String filePath, String fileContent, boolean append) {
if (null == filePath || fileContent == null || filePath.length() < 1 || fileContent.length() < 1) {
log.e("Invalid param. filePath: " + filePath + ", fileContent: " + fileContent);
return false;
}
try {
File file = new File(filePath);
if (!file.exists()) {
if (!file.createNewFile()) {
return false;
}
}
BufferedWriter output = new BufferedWriter(new FileWriter(file, append));
output.write(fileContent);
output.flush();
output.close();
} catch (IOException ioe) {
log.e("writeFile ioe: " + ioe.toString());
return false;
}
return true;
}
public static long getFileSize(String filePath) {
if (null == filePath) {
log.e("Invalid param. filePath: " + filePath);
return 0;
}
File file = new File(filePath);
if (file == null || !file.exists()) {
return 0;
}
return file.length();
}
public static long getFileModifyTime(String filePath) {
if (null == filePath) {
log.e("Invalid param. filePath: " + filePath);
return 0;
}
File file = new File(filePath);
if (file == null || !file.exists()) {
return 0;
}
return file.lastModified();
}
public static boolean setFileModifyTime(String filePath, long modifyTime) {
if (null == filePath) {
log.e("Invalid param. filePath: " + filePath);
return false;
}
File file = new File(filePath);
if (file == null || !file.exists()) {
return false;
}
return file.setLastModified(modifyTime);
}
public static boolean copyFile(ContentResolver cr, String fromPath, String destUri) {
if (null == cr || null == fromPath || fromPath.length() < 1 || null == destUri || destUri.length() < 1) {
log.e("copyFile Invalid param. cr="+cr+", fromPath="+fromPath+", destUri="+destUri);
return false;
}
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(fromPath);
if (null == is) {
log.e("Failed to open inputStream: "+fromPath+"->"+destUri);
return false;
}
// check output uri
String path = null;
Uri uri = null;
String lwUri = destUri.toLowerCase();
if (lwUri.startsWith("content://")) {
uri = Uri.parse(destUri);
} else if (lwUri.startsWith("file://")) {
uri = Uri.parse(destUri);
path = uri.getPath();
} else {
path = destUri;
}
// open output
if (null != path) {
File fl = new File(path);
String pth = path.substring(0, path.lastIndexOf("/"));
File pf = new File(pth);
if (pf.exists() && !pf.isDirectory()) {
pf.delete();
}
pf = new File(pth+File.separator);
if (!pf.exists()) {
if (!pf.mkdirs()) {
log.e("Can't make dirs, path=" + pth);
}
}
pf = new File(path);
if (pf.exists()) {
if (pf.isDirectory()) deleteDirectory(path);
else pf.delete();
}
os = new FileOutputStream(path);
fl.setLastModified(System.currentTimeMillis());
} else {
os = new ParcelFileDescriptor.AutoCloseOutputStream(cr.openFileDescriptor(uri, "w"));
}
// copy file
byte[] dat = new byte[1024];
int i = is.read(dat);
while(-1 != i) {
os.write(dat, 0, i);
i = is.read(dat);
}
is.close();
is = null;
os.flush();
os.close();
os = null;
return true;
} catch(Exception ex) {
log.e("Exception, ex: " + ex.toString());
} finally {
if(null != is) {
try{is.close();} catch(Exception ex) {};
}
if(null != os) {
try{os.close();} catch(Exception ex) {};
}
}
return fal
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码通用DLNA实现手机电视同步播放 (174个子文件)
resources.ap_ 104KB
AllShare.apk 763KB
proguard.cfg 1KB
FileHelper.class 15KB
VideoPlayerActivity.class 10KB
ContentActivity.class 9KB
MusicPlayerActivity.class 9KB
ParseUtil.class 7KB
PicturePlayerActivity.class 7KB
AbstractPlayEngine.class 6KB
ControlRequestProxy.class 5KB
AllShareActivity.class 5KB
DlnaService.class 5KB
CommonUtil.class 4KB
Item.class 4KB
AllShareProxy.class 4KB
FileDownTask.class 4KB
UpnpUtil.class 4KB
ControlCenterRunnable.class 3KB
DeviceBrocastFactory.class 3KB
PicturePlayerActivity$UIManager.class 3KB
PlayBrocastReceiver.class 3KB
ContentAdapter.class 3KB
DeviceAdapter.class 2KB
PlayBorcastFactory.class 2KB
VideoPlayerEngineImpl.class 2KB
VideoPlayerActivity$VideoPlayEngineListener.class 2KB
MusicPlayerActivity$MusicPlayEngineListener.class 2KB
DownLoadHelper.class 2KB
MusicPlayerActivity$SeekbarChangeListener.class 2KB
MediaManager.class 2KB
PicturePlayerActivity$DelCacheFileManager.class 2KB
ContentManager.class 2KB
ItemFactory.class 2KB
DeviceChangeBrocastReceiver.class 2KB
VideoPlayerActivity$SeekbarChangeListener.class 2KB
MusicPlayerEngineImpl.class 1KB
ControlRequestProxy$2.class 1KB
R$drawable.class 1KB
PicturePlayerActivity$1.class 1KB
ControlRequestProxy$1.class 1KB
TalentTimeUtil.class 1KB
R$id.class 1KB
FileManager.class 1KB
VideoPlayerActivity$PlayRunnable.class 1KB
ContentActivity$1.class 1KB
MusicPlayerActivity$1.class 1KB
VideoPlayerActivity$1.class 1KB
DlnaService$1.class 815B
ContentActivity$RequestDirectoryRunnable.class 695B
R$layout.class 647B
AllShareApplication.class 646B
R.class 538B
R$string.class 509B
PlayState.class 498B
CommonUtil$ViewSize.class 485B
ControlRequestProxy$ControlRequestCallback.class 396B
BuildConfig.class 347B
R$attr.class 343B
ControlCenterRunnable$ISearchDeviceListener.class 317B
PlayerEngineListener.class 315B
DownLoadHelper$IDownLoadCallback.class 302B
IPlayEngine.class 276B
fd.class 271B
IDeviceChangeListener.class 181B
.classpath 547B
classes.dex 1.52MB
xercesImpl.jar 1.17MB
xercesImpl-863dba063d6c3fb06df806fad1c3dd1b.jar 544KB
dlna_framework.jar 179KB
dlna_framework-9381b9521e7a5c45fddaa0e25dc25d15.jar 77KB
kxml2-min-2.3.0.jar 10KB
kxml2-min-2.3.0-6a14ec3641cbcb8fe7ddc5760743877e.jar 10KB
annotations-2a37388f62495922ce0006a5c5bbc45b.jar 943B
FileHelper.java 16KB
VideoPlayerActivity.java 10KB
MusicPlayerActivity.java 8KB
PicturePlayerActivity.java 8KB
ContentActivity.java 7KB
ParseUtil.java 7KB
AbstractPlayEngine.java 6KB
ControlRequestProxy.java 5KB
R.java 4KB
UpnpUtil.java 4KB
DlnaService.java 4KB
AllShareActivity.java 4KB
CommonUtil.java 3KB
Item.java 3KB
AllShareProxy.java 3KB
FileDownTask.java 3KB
DeviceAdapter.java 2KB
ControlCenterRunnable.java 2KB
ContentAdapter.java 2KB
DeviceBrocastFactory.java 2KB
PlayBrocastReceiver.java 2KB
PlayBorcastFactory.java 2KB
MediaManager.java 1KB
VideoPlayerEngineImpl.java 1KB
DownLoadHelper.java 1KB
ContentManager.java 1KB
共 174 条
- 1
- 2
资源评论
- wubo11262018-05-16https://github.com/geniusgithub/MediaPlayer.git 开源的地址,可以参考
- 不放棄2020-08-28能借鉴部分
- 互联网大喇叭2017-02-21用特么12年的源码糊弄人 狗
- mrblack1118272018-04-13很有参考价值。。
- killerjava2018-07-19好老的代码
字节晃动
- 粉丝: 4
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功