Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / RetrieveToFilePostProcessor.java
blobb378d2b3989e89471cc9a68c55787c2d71134c61
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;
9 /**
10 * @author Tom Gaskins
11 * @version $Id: RetrieveToFilePostProcessor.java 510 2007-01-17 04:57:40Z ericdalgliesh $
13 public final class RetrieveToFilePostProcessor implements RetrievalPostProcessor
15 java.io.File destination;
17 /**
18 * @param destination
19 * @throws IllegalArgumentException if <code>destination</code> is null
21 public RetrieveToFilePostProcessor(java.io.File destination)
23 if (destination == null)
25 String message = WorldWind.retrieveErrMsg("nullValue.DestNull");
26 WorldWind.logger().log(java.util.logging.Level.FINE, message);
27 throw new IllegalArgumentException(message);
30 this.destination = destination;
33 /**
34 * @param retriever
35 * @return
36 * @throws IllegalArgumentException if <code>retriever</code> is null
38 public java.nio.ByteBuffer run(Retriever retriever)
40 if (retriever == null)
42 String message = WorldWind.retrieveErrMsg("nullValue.RetrieverIsNull");
43 WorldWind.logger().log(java.util.logging.Level.FINE, message);
44 throw new IllegalArgumentException(message);
47 try
49 java.nio.ByteBuffer buffer = retriever.getBuffer();
50 if (buffer == null)
52 WorldWind.logger().log(java.util.logging.Level.FINE, WorldWind.retrieveErrMsg(
53 "RetrieveToFilePostProcessor.NullBufferPostprocessing") + retriever.getName());
54 return null;
57 java.io.FileOutputStream fos = null;
58 try
60 fos = new java.io.FileOutputStream(this.destination);
61 fos.getChannel().write(buffer);
62 return null;
64 catch (java.io.IOException e)
66 throw e;
68 finally
70 if (fos != null)
71 fos.close();
74 catch (java.io.IOException e)
76 String message = WorldWind.retrieveErrMsg("RetrieveToFilePostProcessor.ErrorPostprocessing") + retriever
77 .getName();
78 WorldWind.logger().log(java.util.logging.Level.FINE, message);
79 throw new WWRuntimeException(message, e);