inputstream

AudioTrack Android playing sounds from raw folder

妖精的绣舞 提交于 2019-12-18 04:55:17
问题 Is it possible to play wav files with AudioTrack from the resources folder raw? It tried many ways to reference the raw files in my Android project, but I got a lot of exceptions. This is what I have now, but when I press the button, no sound plays. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button buttonPlayAudioTrack = (Button) findViewById(R.id.buttonPlayAudioTrack); buttonPlayAudioTrack.setOnClickListener(this); int minBufferSize = AudioTrack

What's the difference between InputStream and ByteArrayInputStream?

一个人想着一个人 提交于 2019-12-18 04:54:14
问题 The following code is extracted from the java web start chapter of the core java volume 1. ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream printOut = new PrintStream(out); printOut.print(panel.getText()); //panel.getText() return a String InputStream data = new ByteArrayInputStream(out.toByteArray()); FileSaveService service = (FileSaveService) ServiceManager .lookup("javax.jnlp.FileSaveService"); service.saveFileDialog(".", new String[] { "txt" }, data, "calc.txt");

HttpContext.Current is null in my web service

别等时光非礼了梦想. 提交于 2019-12-18 04:31:35
问题 I have a web service (.svc), and I am trying to capture the SOAP request using a piece of code found elsewhere on StackOverflow. The problem is that HttpContext.Current is null, so I can't access Request.InputString . Why is this null, and how can it be solved? XmlDocument xmlSoapRequest = new XmlDocument(); Stream receiveStream = HttpContext.Current.Request.InputStream; receiveStream.Position = 0; using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {

Input stream reader- read method return wrong value

不问归期 提交于 2019-12-17 23:19:08
问题 This may sound very easy or an old stupid question, but it is quite different for me. I have written a Program for a half-Descending pyramid Pattern which is like this. 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 I know this is very easy, the trick is I don't wanna do this by use of Scanner and Integer.parseInt() . I am trying to do this with BufferedReader and InputStreamReader . So when I execute the following code of my main method with a input of 5 in num. It reads it as 53 when I print it. I have no

Convert InputStream(Image) to ByteArrayInputStream

坚强是说给别人听的谎言 提交于 2019-12-17 22:41:15
问题 Not sure about how I am supposed to do this. Any help would be appreciated 回答1: Read from input stream and write to a ByteArrayOutputStream, then call its toByteArray() to obtain the byte array. Create a ByteArrayInputStream around the byte array to read from it. Here's a quick test: import java.io.*; public class Test { public static void main(String[] arg) throws Throwable { File f = new File(arg[0]); InputStream in = new FileInputStream(f); byte[] buff = new byte[8000]; int bytesRead = 0;

Where to put a text file in Grails, and how to get the path

一世执手 提交于 2019-12-17 22:34:06
问题 I need to read in a .txt file into a groovy class in order to interrogate it line by line. But I am not sure what folder I put it into in my grails app, and how to get the path to it? So far I have tried placing it under src and also in a new folder web-app/txt and I have tried the the following to read it in fileIn = new File('/lexicon.txt').text and fileIn = new File('txt/lexicon.txt').text to no avail. Any body have any pointers? 回答1: Grails is a Java Web Application, so it will be

Why does HTTPURLConnection.getInputStream() takes time

半世苍凉 提交于 2019-12-17 20:54:22
问题 I have a task to download & upload a file using HTTP protocol in Android (Java platform). I am using following code for uploading a file: HttpURLConnection httpURLConnection = (HttpURLConnection) serverUrl.openConnection(); .... httpURLConnection.connect(); OutputStream os = httpURLConnection.getOutputStream(); And Using following code for downloading a file: HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); ... urlConnection.connect(); DataInputStream stream = new

How to timeout a read on Java Socket?

时间秒杀一切 提交于 2019-12-17 20:17:00
问题 I'm trying to read items from a socket and I notice that if there is nothing on the stream of the socket it will stay at the read and back up my application. I wanted to know if there was a way to set a read timeout or terminate the connection after a certain amount of time of nothing in the socket. 回答1: If you write Java, learning to navigate the API documentation is helpful. In the case of a socket read, you can set the timeout option. 回答2: If this socket was created through a URLConnection

How to log request inputstream with HttpModule, then reset InputStream position

主宰稳场 提交于 2019-12-17 18:25:46
问题 I am trying to log the contents of an http request, using an IHttpModule like so: public class LoggingModule : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += ContextBeginRequest; } private void ContextBeginRequest(object sender, EventArgs e) { var request = ((HttpApplication)sender).Request; string content; using (var reader = new StreamReader(request.InputStream)) { content = reader.ReadToEnd(); } LogRequest(content) } } The problem is that after reading

Java - Read file by chunks?

有些话、适合烂在心里 提交于 2019-12-17 17:10:59
问题 I know how to read a file by bytes but cannot find a example how to read it in chunks of bytes. I have a byte array, and i want to read the file by 512bytes and send them over a socket. I have tried by reading total bytes of file and then subtracting 512 bytes until i got a chunk that was less than 512 bytes and signaled EOF and end of transfer. I am trying to implement a TFTP, where data is sent in 512 byte chunks. Anyhow would be thankful for a example. 回答1: You ... read 512 bytes at a time