Skip to content

ServerProxy is a Android library for creating proxy servers to serve files

License

Notifications You must be signed in to change notification settings

eme22/ServerProxy

 
 

Repository files navigation

ServerProxy

ServerProxy is a Android library to provide easy to use classes to create a local server proxies. The following classes exist:

ServerProxy: abstract class which creates a socket and has methods to get a url to reference it.

  • start: Start the proxy listening for requests
  • stop: Stop the proxy listening for requests
  • getPrivateAddress: Get a local url good for being passed internally to another application on the same device
  • getPublicAddress: Get a url good for being passed to another device on the same LAN

FileProxy: Streams whichever file is referenced in the url. Can handle partial requests.

BufferProxy: Streams a file which is being concurrently downloaded. Takes a BufferProgress object to determine when the file is finished downloading. This is useful for serving a song to a MediaPlayer which is still being downloaded. Can only handle one at a time.

  • setBufferFile: Set the buffer file which is used to query for the state of the download

BufferFile: Interface to be implemented, which is queried to get various information about the file being downloaded

  • getFile: Return the file which is being buffered
  • getContentLength: The content length which is passed as a header. ONLY set if you absolutely know for certain the end size of the file
  • getEstimatedSize: The guessed size of the file. It is used to keep track of how much more data needs to be processed. It should be relatively close.
  • isWorkDone: Whether or not the file is done being downloaded
  • onStart: called when the streaming starts
  • onStop: called when the streaming is done

Downloadtask: Runnable to download requested file and implement previous files

EXAMPLE

new DownloadTask(url, new String[]{"Referer"}, new String[]{"www.google.com"}, requireContext(), () -> {

                BufferProxy bufferProxy = new BufferProxy(requireContext());
                bufferProxy.setBufferFile(new BufferFile() {
                    @Override
                    public File getFile() {
                        return new File(requireContext().getExternalCacheDir(), "FILE_PLACEHOLDER.mp4");
                    }

                    @Override
                    public Long getContentLength() {
                        return null;
                    }

                    @Override
                    public long getEstimatedSize() {
                        return 0;
                    }

                    @Override
                    public boolean isWorkDone() {
                        return false;
                    }

                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onStop() {
               
                    }

                    @Override
                    public void onResume() {

                    }
                });
                bufferProxy.start();
                String proxy = bufferProxy.getPrivateAddress("FILE_PLACEHOLDER.mp4");

                ***MORE CODE***


            }).run();

IMPLEMENTATION


implementation 'com.github.eme22:ServerProxy:0.1'

About

ServerProxy is a Android library for creating proxy servers to serve files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%