001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.response;
014
015import java.io.*;
016import java.util.zip.*;
017
018import org.apache.juneau.rest.*;
019import org.apache.juneau.utils.*;
020import org.apache.juneau.utils.ZipFileList.*;
021
022/**
023 * @deprecated No replacement.
024 */
025@Deprecated
026public class ZipFileListResponseHandler implements ResponseHandler {
027
028   @Override /* ResponseHandler */
029   public boolean handle(RestRequest req, RestResponse res) throws IOException, RestException {
030      Object output = res.getOutput();
031      if (output.getClass() == ZipFileList.class) {
032         ZipFileList m = (ZipFileList)output;
033         res.setContentType("application/zip");
034         res.setHeader("Content-Disposition", "attachment;filename=" + m.fileName); //$NON-NLS-2$
035         try (OutputStream os = res.getOutputStream()) {
036            try (ZipOutputStream zos = new ZipOutputStream(os)) {
037               for (ZipFileEntry e : m)
038                  e.write(zos);
039            } catch (Exception e) {
040               e.printStackTrace();
041            }
042         }
043         return true;
044      }
045      return false;
046   }
047
048   @SuppressWarnings("javadoc")
049   public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, RestException {
050      return handle(req, res);
051   }
052}