Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / retrieve / RetrieveToFilePostProcessor.java
blob6b304599f768df96b63491bc08b0ea24082631dd
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.retrieve;
9 import gov.nasa.worldwind.exception.WWRuntimeException;
10 import gov.nasa.worldwind.util.Logging;
12 import java.util.logging.Level;
14 /**
15 * @author Tom Gaskins
16 * @version $Id: RetrieveToFilePostProcessor.java 2471 2007-07-31 21:50:57Z tgaskins $
18 public final class RetrieveToFilePostProcessor implements RetrievalPostProcessor
20 java.io.File destination;
22 /**
23 * @param destination
24 * @throws IllegalArgumentException if <code>destination</code> is null
26 public RetrieveToFilePostProcessor(java.io.File destination)
28 if (destination == null)
30 String message = Logging.getMessage("nullValue.DestNull");
31 Logging.logger().severe(message);
32 throw new IllegalArgumentException(message);
35 this.destination = destination;
38 /**
39 * @param retriever
40 * @return
41 * @throws IllegalArgumentException if <code>retriever</code> is null
43 public java.nio.ByteBuffer run(Retriever retriever)
45 if (retriever == null)
47 String message = Logging.getMessage("nullValue.RetrieverIsNull");
48 Logging.logger().severe(message);
49 throw new IllegalArgumentException(message);
52 try
54 java.nio.ByteBuffer buffer = retriever.getBuffer();
55 if (buffer == null)
57 Logging.logger().log(Level.SEVERE, "RetrieveToFilePostProcessor.NullBufferPostprocessing",
58 retriever.getName());
59 return null;
62 java.io.FileOutputStream fos = null;
63 try
65 fos = new java.io.FileOutputStream(this.destination);
66 fos.getChannel().write(buffer);
67 return null;
69 catch (java.io.IOException e)
71 throw e;
73 finally
75 if (fos != null)
76 fos.close();
79 catch (java.io.IOException e)
81 String message = Logging.getMessage("RetrieveToFilePostProcessor.ErrorPostprocessing", retriever.getName());
82 Logging.logger().severe(message);
83 throw new WWRuntimeException(message, e);