-
-
Save gWOLF3/31868a3234cc70f107c34fae89319b0d to your computer and use it in GitHub Desktop.
How to write in pipes for Android
This file contains hidden or 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
package fr.stackr.android.upt; | |
import java.io.FileNotFoundException; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStreamWriter; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.Log; | |
public class UnixPipeActivity extends Activity { | |
public final static String PATH = "/data/data/fr.stackr.android.upt/pipe/v_pipe"; | |
public final static String TAG = "UPIPE"; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
Log.i(TAG, "Attempt started"); | |
OutputStreamWriter out; | |
try { | |
out = new OutputStreamWriter(new FileOutputStream(PATH)); | |
Log.v(TAG, "SEND :: Try to write the first paragraph ...."); | |
out.write("Try to write the first paragraph ...."); | |
Log.v(TAG, "SEND :: Bip\n"); | |
out.write("Bip\n"); | |
Log.v(TAG, "Flushing..."); | |
out.flush(); | |
Log.v(TAG, "SEND :: Bip post flush"); | |
out.write("Bip post flush"); | |
Log.v(TAG, "Closing…"); | |
out.close(); | |
} catch (FileNotFoundException e) { | |
Log.e(TAG, "Error: the pipe opening failed."); | |
e.printStackTrace(); | |
} catch (IOException e) { | |
Log.e(TAG, "Error: during writing"); | |
e.printStackTrace(); | |
}finally { | |
Log.i(TAG, "Attempt ended"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment