| 1 |
package com.ridelogger.formats; |
| 2 |
|
| 3 |
import java.io.BufferedOutputStream; |
| 4 |
import java.io.File; |
| 5 |
import java.io.FileOutputStream; |
| 6 |
import java.text.SimpleDateFormat; |
| 7 |
import java.util.Date; |
| 8 |
|
| 9 |
import android.os.Environment; |
| 10 |
|
| 11 |
import com.ridelogger.GzipWriter; |
| 12 |
import com.ridelogger.RideService; |
| 13 |
|
| 14 |
|
| 15 |
public class BaseFormat<T> { |
| 16 |
protected GzipWriter buf; |
| 17 |
protected RideService context; |
| 18 |
protected String subExt = ""; |
| 19 |
|
| 20 |
public BaseFormat(RideService rideService) { |
| 21 |
context = rideService; |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
public void createFile() { |
| 26 |
File dir = new File( |
| 27 |
Environment.getExternalStorageDirectory(), |
| 28 |
"Rides" |
| 29 |
); |
| 30 |
|
| 31 |
dir.mkdirs(); |
| 32 |
|
| 33 |
Date startDate = new Date(context.startTime); |
| 34 |
SimpleDateFormat filef = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); |
| 35 |
String fileName = filef.format(startDate) + subExt + ".gz"; |
| 36 |
|
| 37 |
try { |
| 38 |
buf = new GzipWriter(new BufferedOutputStream(new FileOutputStream(new File(dir, fileName)))); |
| 39 |
} catch (Exception e) {} |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
public void writeHeader(){ |
| 44 |
try { |
| 45 |
synchronized (buf) { |
| 46 |
for(CharSequence key : RideService.KEYS) { |
| 47 |
buf.write(key); |
| 48 |
buf.write(","); |
| 49 |
} |
| 50 |
} |
| 51 |
} catch (Exception e) {} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
public void writeValues() { |
| 56 |
try { |
| 57 |
synchronized (buf) { |
| 58 |
for(float value : context.currentValues) { |
| 59 |
buf.write(value); |
| 60 |
} |
| 61 |
} |
| 62 |
} catch (Exception e) {} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
public void writeFooter() { |
| 67 |
try { |
| 68 |
buf.close(); |
| 69 |
} catch (Exception e) {} |
| 70 |
} |
| 71 |
} |