import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileWriter;
public class CamTest implements View.OnClickListener, ILiveViewImage
{
private TextView textview;
private Connection connection;
private FileOutputStream outputStream = null;
+ private FileWriter fileWriter = null;
public CamTest(@NonNull Activity activity)
{
Log.v(TAG, "connect request");
try
{
- //prepareFile();
+ prepareFile(false);
Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.connect, Snackbar.LENGTH_SHORT).show();
Log.v(TAG, "Image : "+ dataValue.length + " bytes.");
// ダミーの記録ファイルが開いていたらファイルに書いておく。
- if (outputStream != null)
- {
- outputStream.write(dataValue, 0, dataValue.length);
- }
+ outputFile(receivedData);
/////// 画像を作る
final Bitmap imageData = BitmapFactory.decodeByteArray(dataValue, 18, (dataValue.length - 18));
}
}
- private void prepareFile()
+ private void outputFile(ReceivedDataHolder receivedData)
+ {
+ try
+ {
+ if (outputStream != null)
+ {
+ final byte[] byteData = receivedData.getData();
+ outputStream.write(byteData, 0, byteData.length);
+ }
+ if (fileWriter != null)
+ {
+ final char[] charData = receivedData.getCharData();
+ fileWriter.write(charData, 0, charData.length);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void prepareFile(boolean isStream)
{
try
{
final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/AirA01a/";
final String outputFileName = "camtest.bin";
File filepath = new File(directoryPath.toLowerCase(), outputFileName.toLowerCase());
- outputStream = new FileOutputStream(filepath);
+ if (isStream) {
+ outputStream = new FileOutputStream(filepath);
+ fileWriter = null;
+ } else {
+ outputStream = null;
+ fileWriter = new FileWriter(filepath);
+ }
}
catch (Exception e)
{
e.printStackTrace();
outputStream = null;
+ fileWriter = null;
}
}
public class ReceivedDataHolder
{
private final byte[] data;
+ private final char[] charData;
ReceivedDataHolder(byte[] data, int length)
{
this.data = Arrays.copyOfRange(data, 0, length);
+ this.charData = null; // Arrays.copyOf(data, length);
}
ReceivedDataHolder(char[] data, int length)
{
+ this.charData = data;
byte[] convertedData = toBytes(data);
this.data = Arrays.copyOfRange(convertedData, 0, length);
}
+ public char[] getCharData()
+ {
+ return (charData);
+ }
+
public byte[] getData()
{
return (data);