/* * $ProjectName$ * $ProjectRevision$ * ----------------------------------------------------------- * $Id$ * ----------------------------------------------------------- * * $Author$ * * Description: * * Copyright 2002-2003 Tor-Einar Jarnbjo * ----------------------------------------------------------- * * Change History * ----------------------------------------------------------- * $Log$ * Revision 1.1 2005/07/11 15:42:36 hcl * Songdb java version, source. only 1.5 compatible * * Revision 1.1.1.1 2004/04/04 22:09:12 shred * First Import * * Revision 1.1 2003/04/10 19:48:22 jarnbjo * no message * */ package de.jarnbjo.ogg; import java.io.*; import java.net.*; import java.util.*; /** * Implementation of the PhysicalOggStream interface for reading * an Ogg stream from a URL. This class performs only the necessary caching * to provide continous playback. Seeking within the stream is not supported. */ public class UncachedUrlStream implements PhysicalOggStream { private boolean closed=false; private URLConnection source; private InputStream sourceStream; private Object drainLock=new Object(); private LinkedList pageCache=new LinkedList(); private long numberOfSamples=-1; private HashMap logicalStreams=new HashMap(); private LoaderThread loaderThread; private static final int PAGECACHE_SIZE = 10; /** Creates an instance of the PhysicalOggStream interface * suitable for reading an Ogg stream from a URL. */ public UncachedUrlStream(URL source) throws OggFormatException, IOException { this.source=source.openConnection(); this.sourceStream=this.source.getInputStream(); loaderThread=new LoaderThread(sourceStream, pageCache); new Thread(loaderThread).start(); while(!loaderThread.isBosDone() || pageCache.size()PAGECACHE_SIZE) { try { Thread.sleep(200); } catch (InterruptedException ex) { } } } } catch(EndOfOggStreamException e) { // ok } catch(IOException e) { e.printStackTrace(); } } public boolean isBosDone() { return bosDone; } } /** * @return always false */ public boolean isSeekable() { return false; } }