Questions tagged [urlstream]

URLStream class provides low-level access to downloading URLs.

The URLStream class provides low-level access to downloading URLs. Data is made available to application code immediately as it is downloaded, instead of waiting until the entire file is complete as with URLLoader. The URLStream class also lets you close a stream before it finishes downloading. The contents of the downloaded file are made available as raw binary data.

The read operations in URLStream are nonblocking. This means that you must use the bytesAvailable property to determine whether sufficient data is available before reading it. An EOFError exception is thrown if insufficient data is available.

All binary data is encoded by default in big-endian format, with the most significant byte first.

The security rules that apply to URL downloading with the URLStream class are identical to the rules applied to URLLoader objects. Policy files may be downloaded as needed. Local file security rules are enforced, and security warnings are raised as needed.

The following example loads a SWF file and parses the beginning of its header to indicate compression and version number information.

To run the example, place a file named URLStreamExample.swf in the same directory as your SWF file.

package {
    import flash.display.Sprite;
    import flash.errors.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import flash.net.URLStream;

    public class URLStreamExample extends Sprite {
        private static const ZLIB_CODE:String = "CWS";
        private var stream:URLStream;

        public function URLStreamExample() {
            stream = new URLStream();
            var request:URLRequest = new URLRequest("URLStreamExample.swf");
            configureListeners(stream);
            try {
                stream.load(request);
            } catch (error:Error) {
                trace("Unable to load requested URL.");
            }
        }

        private function configureListeners(dispatcher:EventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        }

        private function parseHeader():void {
            trace("parseHeader");
            trace("isCompressed: " + isCompressed());
            trace("version: " + stream.readByte());
        }

        private function isCompressed():Boolean {
            return (stream.readUTFBytes(3) == ZLIB_CODE);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
            parseHeader();
        }

        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:Event):void {
            trace("progressHandler: " + event);
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        private function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }
    }
}
15 questions
13
votes
6 answers

Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1

I am using Android's MediaPlayer to set up a URL stream in my application. I have tried several different posts to deal with the exit code and error: (1, -2147483648). I have attempted several different streams, but I can't seem to get the…
Lonely Twinky
  • 435
  • 1
  • 6
  • 17
2
votes
1 answer

MP3 stream returning WF: _WebFilterIsActive returning: NO on device

Currently streaming an mp3 with the following code: NSString *stream = @"http://k003.kiwi6.com/hotlink/o4ywrn3ejt/Exodus.mp3"; NSURL *url = [NSURL URLWithString:stream]; NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url]; …
knowles3226
  • 65
  • 1
  • 7
1
vote
0 answers

URLRequest in AS3 can't read the correct content when server return 403

I'm using URLRequest in a Flash client to get some information from a service, the service will check the parameter in the request url, if the parameter is invalid, the server may return 403 with some content in http body, and I need analyse the…
1
vote
0 answers

How can I return a URLConnection given a byte array

I need to render an html document that can have images stored both internally and externally. To render I use a library that will load these images by their urls (as referenced in the html). What I'm doing is: for external images I use http:// urls…
Victor Basso
  • 5,556
  • 5
  • 42
  • 60
1
vote
2 answers

How would I enter text into a website with java?

I'm just trying to find out how to tell java to open a website and enter text (preferably a string value) into a text field For example go to Google and search any text( it does not have to be user entered) I realize that it wont actually open any…
anthoK
  • 31
  • 1
  • 3
1
vote
2 answers

play flv using netStream appendBytes

I know that there are many ways to play an FLV file but considering my project requirements, I need to play the flv using URLStream and NetStream here's the complete sample code that I'm doing my tests on: package { import…
Hadi tavakoli
  • 1,267
  • 2
  • 16
  • 30
0
votes
1 answer

Flash AS3 read proxy server response with URLLoader

I am running an embedded flash 'swf' inside a LAN network with a proxy server. Proxy server interrupts some urls and returns my usage information. I am trying to access this information by sending those urls. I can see this traffic in firebug ,But…
feminkk
  • 1,135
  • 2
  • 14
  • 18
0
votes
1 answer

Why does URLStream sometimes not fire Event.COMPLETE?

I've got an application that is downloading several large binary files and saving them to disk. On some machines it works fine and on some other machines every once in a while a download will proceed to 99.9% complete and the URLStream object will…
Phil
  • 11
  • 1
0
votes
1 answer

Passing Parameter from URL string in Header() redirect to another page in PHP

I want to pass the URL string data to dashboard.php from login.php here I have just a login auth whereas the data present in the URL is been carried from homepage.php form to login via URL string, I want to carry forward this string to dashboard The…
0
votes
0 answers

Java.net URLConnection.setContentHandlerFactory doesn't work?

I am attempting to solve a problem by extending URLStreamHandler with the goal of providing a file from memory. I have the class... public class CustomURLStreamHandler extends URLStreamHandler { private Handler fileHandler = new Handler(); …
Lane
  • 685
  • 2
  • 10
  • 25
0
votes
1 answer

ReadByte from URLStream failed in ActionScript Flash Builder

I'm new to ActionScript and have some problem with getting bytes from URLStream. I'm trying to connect to a URL, and get the bytes from this URL. I created private var urs:URLStream; and urs.connected returns true. Now I want to get the byte from…
kande
  • 559
  • 1
  • 10
  • 28
0
votes
1 answer

android URL stream cannot get whole data

I'm trying to get youtube download link by using this String data = getURL("http://www.youtube.com/get_video_info?video_id=" + id); but It always return a part of data. The end of data is like "..." for…
Lion.k
  • 2,519
  • 8
  • 28
  • 43
0
votes
1 answer

Adobe Air multi-download

I have been searching both the web and stackoverflow for a complete answer to implementing multiple downloads of mp3 files downloadManager. I have read a number of post and realize the most efficient facilities are to use ByteArray, URLStream and…
0
votes
1 answer

Is there a method like URLStream in as2?

i need to receive data continuously from server to flash client and it is possible in as3 with this code : public class ASHXTest extends Sprite { public function ASHXTest() { this.init(); } …
0
votes
1 answer

AS3 URLStream cuts off first 4 characters of response

I have a URLStream object which accepts an XML formatted response but unfortunately the first 4 characters of the response are being chopped off, making the xml malformed. The xml being returned from the server is correctly formatted if I use a…
crooksy88
  • 3,849
  • 1
  • 24
  • 30