Advertisement
anine444

Untitled

Oct 19th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. /*
  2. * Copyright (c) 2008, Christophe Delory
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY CHRISTOPHE DELORY ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL CHRISTOPHE DELORY BE LIABLE FOR ANY
  18. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package org.messic.server.playlists.m3u;
  26.  
  27. import java.io.BufferedWriter;
  28. import java.io.OutputStream;
  29. import java.io.OutputStreamWriter;
  30. import java.util.ArrayList;
  31. import java.util.List;
  32.  
  33. import org.messic.server.playlists.Media;
  34. import org.messic.server.playlists.Playlist;
  35. import org.messic.server.playlists.SpecificPlaylist;
  36. import org.messic.server.playlists.SpecificPlaylistProvider;
  37. import org.messic.server.playlists.content.Content;
  38.  
  39. /**
  40. * A M3U, M4U, or Real Audio Metadata playlist.
  41. *
  42. * @version $Revision: 92 $
  43. * @author Christophe Delory
  44. */
  45. public class M3U
  46. implements SpecificPlaylist
  47. {
  48. /**
  49. * The provider of this specific playlist.
  50. */
  51. private transient SpecificPlaylistProvider _provider = null;
  52.  
  53. /**
  54. * The list of child resources.
  55. */
  56. private final List<Resource> _resources = new ArrayList<Resource>();
  57.  
  58. /**
  59. * <code>true</code> if the marshalled playlist must be an Extension M3U, <code>false</code> otherwise.
  60. */
  61. private boolean _extensionM3U = false;
  62.  
  63. @Override
  64. public void setProvider( final SpecificPlaylistProvider provider )
  65. {
  66. _provider = provider;
  67. }
  68.  
  69. @Override
  70. public SpecificPlaylistProvider getProvider()
  71. {
  72. return _provider;
  73. }
  74.  
  75. @Override
  76. public void writeTo( final OutputStream out, final String encoding )
  77. throws Exception
  78. {
  79. String enc = encoding;
  80.  
  81. if ( enc == null )
  82. {
  83. enc = "UTF-8"; // For the M3U8 case. FIXME US-ASCII?
  84. }
  85.  
  86. final BufferedWriter writer = new BufferedWriter( new OutputStreamWriter( out, enc ) ); // Throws
  87. // NullPointerException
  88. // if out is null. May
  89. // throw
  90. // UnsupportedEncodingException.
  91.  
  92. if ( _extensionM3U )
  93. {
  94. writer.write( "#EXTM3U" ); // May throw IOException.
  95. writer.newLine(); // May throw IOException.
  96. }
  97.  
  98. for ( Resource resource : _resources )
  99. {
  100. if ( _extensionM3U )
  101. {
  102. writer.write( "#EXTINF:" ); // May throw IOException.
  103. writer.write( Long.toString( resource.getLength() ) ); // May throw IOException.
  104. writer.write( "," ); // May throw IOException.
  105.  
  106. if ( resource.getName() == nu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement