merged 1.1 branch into head
[mir.git] / source / mircoders / media / MediaHandlerOgg.java
index d518f8b..4954437 100755 (executable)
  */
 package  mircoders.media;
 
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
 import mir.entity.Entity;
 import mir.log.LoggerWrapper;
 import mir.media.MediaExc;
 import mir.media.MediaFailure;
 import mir.media.MediaHandler;
-import mir.misc.FileUtil;
 import mir.misc.StringUtil;
+import mir.util.IORoutines;
+
+import java.io.File;
+import java.io.FileOutputStream;
 
 /**
  * Please note: this media handler produces
@@ -71,8 +68,7 @@ import mir.misc.StringUtil;
 
 public class MediaHandlerOgg extends MediaHandlerAudio implements MediaHandler
 {
-  protected LoggerWrapper logger;
-
+  
   public MediaHandlerOgg() {
     logger = new LoggerWrapper("Media.Audio.Ogg");
   }
@@ -86,55 +82,20 @@ public class MediaHandlerOgg extends MediaHandlerAudio implements MediaHandler
     String date = ent.getFieldValue("date");
     String datePath = StringUtil.webdbDate2path(date);
     String oggPointer = getPublishHost() + ent.getFieldValue("publish_path");
-    //String mpegURLFile = baseName + ".m3u";
     String playlistFile = baseName + ".pls";
 
     try {
-      //write the "meta" files
-      //first the .m3u since it only contains one line
-      //dont write the .m3u it is an ogg vorbis file
-      //FileUtil.write(getStoragePath() + "/" + datePath + "/" + mpegURLFile,
-        //new StringReader(mp3Pointer), "US-ASCII");
-      //now the .pls file
-      FileUtil.write(getStoragePath() + "/" + datePath + "/" + playlistFile,
-                     new StringReader(oggPointer), "US-ASCII");
+      IORoutines.writeStream(oggPointer, "us-ascii",
+          new FileOutputStream(getBaseStoragePath() + File.separator + datePath + File.separator  + playlistFile));
+          reportChange(getBaseStoragePath() + File.separator + datePath + File.separator  + playlistFile);
     }
     catch (Throwable e) {
-      logger.error("MediaHandlerOgg.produce: " + e.toString());
+      logger.error("MediaHandlerOgg.execute: " + e.toString());
 
       throw new MediaFailure(e);
     }
   }
 
-  public List getURL(Entity ent, Entity mediaTypeEnt) {
-    List theList = new Vector();
-
-    //String stringSize = ent.getFieldValue("size");
-    //int size = Integer.parseInt(stringSize, 10)/1024;
-    theList.add(ent);
-
-    String basePath = StringUtil.regexpReplace(ent.getFieldValue("publish_path"),
-                                               ".ogg$", "");
-
-    // @todo the texts ("title") below urgently need to be sanely localizaeble
-    // somehow
-    //no .m3u!
-    //Map m3uHash = new HashMap();
-    //m3uHash.put("publish_path", basePath + ".m3u");
-    //m3uHash.put("publish_server", ent.getFieldValue("publish_server"));
-    //m3uHash.put("title", "stream URL");
-    //theList.add(m3uHash);
-
-    Map plsHash = new HashMap();
-    plsHash.put("publish_path", basePath + ".pls");
-    plsHash.put("publish_server", ent.getFieldValue("publish_server"));
-    plsHash.put("title", "playlist URL");
-    theList.add(plsHash);
-
-    return theList;
-
-  }
-
   public String getDescr(Entity mediaType) {
     return "ogg";
   }