Example usage for java.util.zip DataFormatException getLocalizedMessage

List of usage examples for java.util.zip DataFormatException getLocalizedMessage

Introduction

In this page you can find the example usage for java.util.zip DataFormatException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.archive.wayback.replay.swf.SWFReplayRenderer.java

@Override
public void renderResource(HttpServletRequest httpRequest, HttpServletResponse httpResponse,
        WaybackRequest wbRequest, CaptureSearchResult result, Resource httpHeadersResource,
        Resource payloadResource, ResultURIConverter uriConverter, CaptureSearchResults results)
        throws ServletException, IOException, WaybackException {

    try {//from  w  w  w. j  av  a 2  s. c o m

        // copy HTTP response code:
        HttpHeaderOperation.copyHTTPMessageHeader(httpHeadersResource, httpResponse);

        // load and process original headers:
        Map<String, String> headers = HttpHeaderOperation.processHeaders(httpHeadersResource, result,
                uriConverter, httpHeaderProcessor);

        // The URL of the resource, for resolving embedded relative URLs:
        URL url = null;
        try {
            url = new URL(result.getOriginalUrl());
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
            throw new IOException(e1.getMessage());
        }
        // the date to associate with the embedded, rewritten URLs:
        String datespec = result.getCaptureTimestamp();
        SWFUrlRewriter rw = new SWFUrlRewriter(uriConverter, url, datespec);

        // OK, try to read the input movie:
        Movie movie = getRobustMovie(RobustMovieDecoder.DECODE_RULE_NULLS);

        try {
            movie.decodeFromStream(payloadResource);
        } catch (DataFormatException e1) {
            throw new BadContentException(e1.getLocalizedMessage());
        }
        Movie outMovie = new Movie(movie);

        List<MovieTag> inTags = movie.getObjects();
        ArrayList<MovieTag> outTags = new ArrayList<MovieTag>();
        for (MovieTag tag : inTags) {
            outTags.add(rewriteTag(rw, tag));
        }
        outMovie.setObjects(outTags);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            outMovie.encodeToStream(baos);
        } catch (DataFormatException e) {
            throw new BadContentException(e.getLocalizedMessage());
        }

        // put the new corrected length:
        headers.put(HttpHeaderOperation.HTTP_LENGTH_HEADER, String.valueOf(baos.size()));

        // send the new headers:
        HttpHeaderOperation.sendHeaders(headers, httpResponse);

        // and copy the stored up byte-stream:
        baos.writeTo(httpResponse.getOutputStream());
    } catch (Exception e) {

        // Redirect to identity if there are any issues
        throw new BetterRequestException(UrlOperations.computeIdentityUrl(wbRequest));
    }
}