-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gowtham.balamurugan
committed
Jun 26, 2023
1 parent
0d85c6e
commit cfdb52c
Showing
5 changed files
with
131 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
library/src/main/java/com/gowtham/library/utils/FileCacheHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.gowtham.library.utils; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class FileCacheHandler { | ||
|
||
public static String putFileInCache(Context context, InputStream fis) | ||
{ | ||
|
||
FileOutputStream fos=null; | ||
try | ||
{ | ||
File f=new File(context.getCacheDir(), "temp_video_file"); | ||
if(f.exists()){ | ||
f.delete(); | ||
} | ||
fos=new FileOutputStream(f); | ||
CopyStream(fis,fos); | ||
return f.getAbsolutePath(); | ||
} | ||
catch(Exception e) | ||
{ | ||
LogMessage.e(Log.getStackTraceString(e)); | ||
return ""; | ||
} | ||
finally | ||
{ | ||
try | ||
{ | ||
fos.flush(); | ||
fos.close(); | ||
} catch (Exception e) { | ||
LogMessage.e(Log.getStackTraceString(e)); | ||
} | ||
} | ||
} | ||
|
||
public static void CopyStream(InputStream is, OutputStream os) | ||
{ | ||
final int buffer_size = 1024; | ||
try { | ||
|
||
byte[] bytes = new byte[buffer_size]; | ||
for (; ; ) { | ||
|
||
int count = is.read(bytes, 0, buffer_size); | ||
if (count == -1) { | ||
break; | ||
} | ||
os.write(bytes, 0, count); | ||
os.flush(); | ||
} | ||
} catch (Exception ex) { | ||
LogMessage.e(Log.getStackTraceString(ex)); | ||
} | ||
} | ||
} |
Oops, something went wrong.