Skip to content

Instantly share code, notes, and snippets.

@rbochet
Created May 18, 2011 03:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rbochet/977955 to your computer and use it in GitHub Desktop.
Save rbochet/977955 to your computer and use it in GitHub Desktop.
How to write in pipes for Android
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");
}
}
}
@F-Sidney
Copy link

Hi,rbochet:

I tried this gist, and it works fine with ffmpeg with pipe protocol on android,
however, the "v_pipe“ is not actually a named pipe, it's just a file, right?
because when I use "ls -l", it shows -rw----, but named pipe file would show as "prw----"
also the file size is keeping increment, which named pipe shouldn't.
so, my question is: is it a named pipe?

anyway, thanks for your gist, it really help, I'm from here
http://stackoverflow.com/questions/6026360/how-to-use-unix-pipes-in-android

@F-Sidney
Copy link

Sorry, I forget the mkfifo function in C, now it is a named pipe and works fine.

@corwin-of-amber
Copy link

@F-Sidney, can you also create the named pipe in Java?

@F-Sidney
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment