/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.exoplayer2.source.hls.offline;

import android.net.Uri;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.SegmentDownloadAction;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/** An action to download or remove downloaded HLS streams. */
public final class HlsDownloadAction extends SegmentDownloadAction<String> {

  public static final Deserializer DESERIALIZER = new SegmentDownloadActionDeserializer<String>() {

    @Override
    public String getType() {
      return TYPE;
    }

    @Override
    protected String readKey(DataInputStream input) throws IOException {
      return input.readUTF();
    }

    @Override
    protected String[] createKeyArray(int keyCount) {
      return new String[0];
    }

    @Override
    protected DownloadAction createDownloadAction(Uri manifestUri, boolean removeAction,
        String data, String[] keys) {
      return new HlsDownloadAction(manifestUri, removeAction, data, keys);
    }

  };

  private static final String TYPE = "HlsDownloadAction";

  /** @see SegmentDownloadAction#SegmentDownloadAction(Uri, boolean, String, Object[]) */
  public HlsDownloadAction(Uri manifestUri, boolean removeAction, String data, String... keys) {
    super(manifestUri, removeAction, data, keys);
  }

  @Override
  protected String getType() {
    return TYPE;
  }

  @Override
  protected HlsDownloader createDownloader(DownloaderConstructorHelper constructorHelper) {
    HlsDownloader downloader = new HlsDownloader(manifestUri, constructorHelper);
    if (!isRemoveAction()) {
      downloader.selectRepresentations(keys);
    }
    return downloader;
  }

  @Override
  protected void writeKey(DataOutputStream output, String key) throws IOException {
    output.writeUTF(key);
  }

}

@@ -1183,16 +1183,22 @@
 ALIZER =
+%0A     
  new Seg
@@ -1241,16 +1241,20 @@
 g%3E() %7B%0A%0A
+    
     @Ove
@@ -1255,24 +1255,28 @@
   @Override%0A
+    
     public S
@@ -1295,24 +1295,28 @@
 e() %7B%0A      
+    
 return TYPE;
@@ -1316,27 +1316,35 @@
 n TYPE;%0A    
+   
+ 
 %7D%0A%0A
+    
     @Overrid
@@ -1341,32 +1341,36 @@
   @Override%0A    
+ 
+   
 protected String
@@ -1424,24 +1424,28 @@
 ion %7B%0A      
+    
 return input
@@ -1456,16 +1456,20 @@
 dUTF();%0A
+    
     %7D%0A%0A 
@@ -1463,32 +1463,36 @@
 %0A        %7D%0A%0A    
+  
+  
 @Override%0A    pr
@@ -1477,32 +1477,36 @@
       @Override%0A
+    
     protected St
@@ -1541,32 +1541,36 @@
 yCount) %7B%0A      
+    
 return new Strin
@@ -1575,19 +1575,34 @@
 ing%5B
-0%5D;%0A
+keyCount%5D;%0A   
     
+ 
 %7D%0A%0A
+    
     
@@ -1607,24 +1607,28 @@
   @Override%0A
+    
     protecte
@@ -1657,32 +1657,45 @@
 eDownloadAction(
+%0A            
 Uri manifestUri,
@@ -1716,24 +1716,16 @@
 eAction,
-%0A       
  String 
@@ -1749,24 +1749,28 @@
 ys) %7B%0A      
+    
 return new H
@@ -1830,19 +1830,26 @@
 s);%0A    
-%7D%0A%0A
+    %7D%0A    
   %7D;%0A%0A  

Fix FilteringHlsPlaylistParser