You are viewing a plain text version of this content. The canonical link for it is here.
Posted to droids-commits@incubator.apache.org by th...@apache.org on 2010/04/30 17:06:26 UTC
svn commit: r939738 -
/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java
Author: thorsten
Date: Fri Apr 30 17:06:25 2010
New Revision: 939738
URL: http://svn.apache.org/viewvc?rev=939738&view=rev
Log:
white noise - formating changes
Modified:
incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java
Modified: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java?rev=939738&r1=939737&r2=939738&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java (original)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java Fri Apr 30 17:06:25 2010
@@ -39,106 +39,106 @@ import org.apache.droids.api.Handler;
*/
public class Save extends WriterHandler implements Handler {
- private String outputDir = null;
+ private String outputDir = null;
- private URI uri = null;
+ private URI uri = null;
- private boolean includeHost = false;
- protected int bufferSize=8192;
-
- public void handle(URI uri, ContentEntity entity) throws IOException {
- this.uri = uri;
- InputStream instream = entity.obtainContent();
- try {
- writeOutput(instream);
- } finally {
- instream.close();
- }
- }
-
- private void writeOutput(InputStream stream) throws IOException {
- if (!uri.getPath().endsWith("/")) {
- byte[] buffer = new byte[bufferSize];
- int length = -1;
-
- String file = outputDir;
- if (includeHost) {
- file += uri.getHost() + uri.getPath();
- } else {
- file += uri.getPath().substring(1);
- }
- log.info("Trying to save " + uri + " to " + file);
- File cache = new File(file);
- OutputStream output =null;
- try {
- createFile(cache);
- output = new BufferedOutputStream(new FileOutputStream(cache));
-
- while ((length = stream.read(buffer)) > -1) {
- output.write(buffer, 0, length);
+ private boolean includeHost = false;
+ protected int bufferSize = 8192;
+
+ public void handle(URI uri, ContentEntity entity) throws IOException {
+ this.uri = uri;
+ InputStream instream = entity.obtainContent();
+ try {
+ writeOutput(instream);
+ } finally {
+ instream.close();
+ }
+ }
+
+ private void writeOutput(InputStream stream) throws IOException {
+ if (!uri.getPath().endsWith("/")) {
+ byte[] buffer = new byte[bufferSize];
+ int length = -1;
+
+ String file = outputDir;
+ if (includeHost) {
+ file += uri.getHost() + uri.getPath();
+ } else {
+ file += uri.getPath().substring(1);
+ }
+ log.info("Trying to save " + uri + " to " + file);
+ File cache = new File(file);
+ OutputStream output = null;
+ try {
+ createFile(cache);
+ output = new BufferedOutputStream(new FileOutputStream(cache));
+
+ while ((length = stream.read(buffer)) > -1) {
+ output.write(buffer, 0, length);
+ }
+
+ } catch (IOException e) {
+ throw e;
+ } finally {
+ if (null != output) {
+ output.flush();
+ output.close();
+ }
+ }
}
-
- } catch (IOException e) {
- throw e;
- } finally{
- if (null != output) {
- output.flush();
- output.close();
+ }
+
+ public static void createFile(File cache) throws IOException {
+ if (!cache.isDirectory() && !cache.getAbsolutePath().endsWith("/")) {
+ try {
+ cache.createNewFile();
+ } catch (IOException e) {
+ // if we cannot create a file that means that the parent path
+ // does not exists
+ File path = new File(cache.getParent());
+ path.mkdirs();
+ cache.createNewFile();
+ }
}
}
+
+ /**
+ * Get the directory where we want to save the stream.
+ *
+ * @return directory where we want to save the stream.
+ */
+ public String getOutputDir() {
+ return outputDir;
+ }
+
+ /**
+ * Set the directory where we want to save the stream.
+ *
+ * @param outputDir
+ * the directory where we want to save the stream.
+ */
+ public void setOutputDir(String outputDir) {
+ this.outputDir = outputDir;
}
- }
- public static void createFile(File cache) throws IOException {
- if (!cache.isDirectory() && !cache.getAbsolutePath().endsWith("/")) {
- try {
- cache.createNewFile();
- } catch (IOException e) {
- // if we cannot create a file that means that the parent path
- // does not exists
- File path = new File(cache.getParent());
- path.mkdirs();
- cache.createNewFile();
- }
- }
- }
-
- /**
- * Get the directory where we want to save the stream.
- *
- * @return directory where we want to save the stream.
- */
- public String getOutputDir() {
- return outputDir;
- }
-
- /**
- * Set the directory where we want to save the stream.
- *
- * @param outputDir
- * the directory where we want to save the stream.
- */
- public void setOutputDir(String outputDir) {
- this.outputDir = outputDir;
- }
-
- /**
- * Do we want to prefix the export dir with the host name.
- *
- * @return true if we want to use the prefix; false otherwise
- */
- public boolean isIncludeHost() {
- return includeHost;
- }
-
- /**
- * Do we want to prefix the export dir with the host name.
- *
- * @param includeHost
- * true if we want to use the prefix; false otherwise
- */
- public void setIncludeHost(boolean includeHost) {
- this.includeHost = includeHost;
- }
+ /**
+ * Do we want to prefix the export dir with the host name.
+ *
+ * @return true if we want to use the prefix; false otherwise
+ */
+ public boolean isIncludeHost() {
+ return includeHost;
+ }
+
+ /**
+ * Do we want to prefix the export dir with the host name.
+ *
+ * @param includeHost
+ * true if we want to use the prefix; false otherwise
+ */
+ public void setIncludeHost(boolean includeHost) {
+ this.includeHost = includeHost;
+ }
}