From: <bra...@us...> - 2008-06-24 23:41:31
|
Revision: 2310 http://archive-access.svn.sourceforge.net/archive-access/?rev=2310&view=rev Author: bradtofel Date: 2008-06-24 16:41:39 -0700 (Tue, 24 Jun 2008) Log Message: ----------- REFACTOR: moving index update code to separate package. Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/IndexClient.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/RemoteSubmitFilter.java Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/IndexClient.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/RemoteSubmitFilter.java Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/IndexClient.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/IndexClient.java 2008-06-24 23:40:15 UTC (rev 2309) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/IndexClient.java 2008-06-24 23:41:39 UTC (rev 2310) @@ -1,204 +0,0 @@ -/* IndexClient - * - * $Id$ - * - * Created on 4:22:52 PM Oct 12, 2006. - * - * Copyright (C) 2006 Internet Archive. - * - * This file is part of Wayback. - * - * Wayback is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Wayback is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Wayback; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package org.archive.wayback.resourceindex.indexer; - -import java.io.File; -import java.io.BufferedOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Iterator; -import java.util.logging.Logger; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.InputStreamRequestEntity; -import org.apache.commons.httpclient.methods.PutMethod; -import org.archive.wayback.core.SearchResult; -import org.archive.wayback.resourceindex.cdx.SearchResultToCDXLineAdapter; -import org.archive.wayback.util.AdaptedIterator; -import org.archive.wayback.util.Adapter; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class IndexClient { - private static final Logger LOGGER = Logger.getLogger(IndexClient - .class.getName()); - - private String target = null; - private File tmpDir = null; - - private HttpClient client = new HttpClient(); - - /** - * @param cdx - * @return true if CDX was added to local or remote index - * @throws HttpException - * @throws IOException - */ - public boolean addCDX(File cdx) throws HttpException, IOException { - boolean added = false; - if(target == null) { - throw new IOException("No target set"); - } - String base = cdx.getName(); - if(target.startsWith("http://")) { - String finalUrl = target; - if(target.endsWith("/")) { - finalUrl = target + base; - } else { - finalUrl = target + "/" + base; - } - PutMethod method = new PutMethod(finalUrl); - method.setRequestEntity(new InputStreamRequestEntity( - new FileInputStream(cdx))); - - int statusCode = client.executeMethod(method); - if (statusCode == HttpStatus.SC_OK) { - LOGGER.info("Uploaded cdx " + cdx.getAbsolutePath() + " to " + - finalUrl); - if(!cdx.delete()) { - throw new IOException("FAILED delete " + - cdx.getAbsolutePath()); - } - - added = true; - } else { - throw new IOException("Method failed: " + method.getStatusLine() - + " for URL " + finalUrl + " on file " - + cdx.getAbsolutePath()); - } - - } else { - // assume a local directory: - File toBeMergedDir = new File(target); - if(!toBeMergedDir.exists()) { - toBeMergedDir.mkdirs(); - } - if(!toBeMergedDir.exists()) { - throw new IOException("Target " + target + " does not exist"); - } - if(!toBeMergedDir.isDirectory()) { - throw new IOException("Target " + target + " is not a dir"); - } - if(!toBeMergedDir.canWrite()) { - throw new IOException("Target " + target + " is not writable"); - } - File toBeMergedFile = new File(toBeMergedDir,base); - if(toBeMergedFile.exists()) { - LOGGER.severe("WARNING: "+toBeMergedFile.getAbsolutePath() + - "already exists!"); - } else { - if(cdx.renameTo(toBeMergedFile)) { - LOGGER.info("Queued " + toBeMergedFile.getAbsolutePath() + - " for merging."); - added = true; - } else { - LOGGER.severe("FAILED rename("+cdx.getAbsolutePath()+ - ") to ("+toBeMergedFile.getAbsolutePath()+")"); - } - } - } - return added; - } - - /** - * @param base - * @param itr - * @return true if data was added to local or remote index - * @throws HttpException - * @throws IOException - */ - public boolean addSearchResults(String base, Iterator<SearchResult> itr) - throws HttpException, IOException { - - if(tmpDir == null) { - throw new IOException("No tmpDir argument"); - } - File tmpFile = new File(tmpDir,base); - if(tmpFile.exists()) { - // TODO: is this safe? - if(!tmpFile.delete()) { - throw new IOException("Unable to remove tmp " + - tmpFile.getAbsolutePath()); - } - } - FileOutputStream os = new FileOutputStream(tmpFile); - BufferedOutputStream bos = new BufferedOutputStream(os); - PrintWriter pw = new PrintWriter(bos); - - Adapter<SearchResult,String> adapterSRtoS = - new SearchResultToCDXLineAdapter(); - Iterator<String> itrS = - new AdaptedIterator<SearchResult,String>(itr,adapterSRtoS); - - while(itrS.hasNext()) { - pw.println(itrS.next()); - } - pw.close(); - boolean added = addCDX(tmpFile); - return added; - } - - /** - * @return the target - */ - public String getTarget() { - return target; - } - - /** - * @param target the target to set - */ - public void setTarget(String target) { - this.target = target; - } - - /** - * @return the tmpDir - */ - public String getTmpDir() { - if(tmpDir == null) { - return null; - } - return tmpDir.getAbsolutePath(); - } - - /** - * @param tmpDir the tmpDir to set - */ - public void setTmpDir(String tmpDir) { - this.tmpDir = new File(tmpDir); - if(!this.tmpDir.isDirectory()) { - this.tmpDir.mkdirs(); - } - } -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/RemoteSubmitFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/RemoteSubmitFilter.java 2008-06-24 23:40:15 UTC (rev 2309) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/RemoteSubmitFilter.java 2008-06-24 23:41:39 UTC (rev 2310) @@ -1,187 +0,0 @@ -/* RemoteSubmitFilter - * - * $Id$ - * - * Created on 3:57:00 PM Oct 12, 2006. - * - * Copyright (C) 2006 Internet Archive. - * - * This file is part of Wayback. - * - * Wayback is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Wayback is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Wayback; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package org.archive.wayback.resourceindex.indexer; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.util.Enumeration; -import java.util.Properties; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Filter that accepts PUT HTTP requests to insert CDX files into the incoming - * directory for a local BDBIndex. - * - * @author brad - * @version $Date$, $Revision$ - */ -public class RemoteSubmitFilter implements Filter { - - private final static String INCOMING_PATH = "config-tmp.incoming"; - private final static String HTTP_PUT_METHOD = "PUT"; - private File incoming = null; - private File tmpIncoming = null; - - // TODO: get rid of this - @SuppressWarnings("unchecked") - public void init(FilterConfig c) throws ServletException { - - Properties p = new Properties(); - ServletContext sc = c.getServletContext(); - for (Enumeration e = sc.getInitParameterNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - p.put(key, sc.getInitParameter(key)); - } - for (Enumeration e = c.getInitParameterNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - p.put(key, c.getInitParameter(key)); - } - - String cfgName = INCOMING_PATH; - String incomingPath = p.getProperty(cfgName); - if((incomingPath == null) || incomingPath.length() == 0) { - throw new ServletException("Invalid or missing " + cfgName + - " configuration"); - } - incoming = new File(incomingPath); - tmpIncoming = new File(incoming,"tmp"); - try { - ensureDir(incoming); - ensureDir(tmpIncoming); - } catch (IOException e) { - throw new ServletException(e); - } - } - private void ensureDir(File dir) throws IOException { - if(dir.exists()) { - if(!dir.isDirectory()) { - throw new IOException("Path " + dir.getAbsolutePath() + - "exists but is not a directory."); - } - } else { - if(!dir.mkdirs()) { - throw new IOException("FAILED mkdir " + dir.getAbsolutePath()); - } - } - } - - /* - * (non-Javadoc) - * - * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, - * javax.servlet.ServletResponse, javax.servlet.FilterChain) - */ - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - if (!handle(request, response)) { - chain.doFilter(request, response); - } - } - /** - * @param request - * @param response - * @return boolean, true unless something went wrong.. - * @throws IOException - * @throws ServletException - */ - protected boolean handle(final ServletRequest request, - final ServletResponse response) throws IOException, - ServletException { - if (!(request instanceof HttpServletRequest)) { - return false; - } - if (!(response instanceof HttpServletResponse)) { - return false; - } - HttpServletRequest httpRequest = (HttpServletRequest) request; - if(httpRequest.getMethod().equals(HTTP_PUT_METHOD)) { - - return handlePut(httpRequest,response); - - } - return false; - } - - protected boolean handlePut(final HttpServletRequest request, - final ServletResponse response) throws IOException, - ServletException { - - String reqURI = request.getRequestURI(); - int lastSlashIdx = reqURI.lastIndexOf("/"); - if (lastSlashIdx == -1) { - return false; - } - String targetFileName = reqURI.substring(lastSlashIdx + 1); - String tmpFileName = targetFileName + ".tmp"; - File tmpFile = new File(tmpIncoming,tmpFileName); - File targetFile = new File(incoming, targetFileName); - - int i; - InputStream input; - input = request.getInputStream(); - BufferedInputStream in = new BufferedInputStream(input); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - FileWriter out = new FileWriter(tmpFile); - - while ((i = reader.read()) != -1) { - out.write(i); - } - - out.close(); - in.close(); - if (!tmpFile.renameTo(targetFile)) { - throw new IOException("Unable to rename " - + tmpFile.getAbsolutePath() + " to " - + targetFile.getAbsolutePath()); - } - - PrintWriter outHTML = response.getWriter(); - outHTML.println("done"); - return true; - } - - /* (non-Javadoc) - * @see javax.servlet.Filter#destroy() - */ - public void destroy() { - // TODO Auto-generated method stub - - } -} Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/IndexClient.java (from rev 2302, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/IndexClient.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/IndexClient.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/IndexClient.java 2008-06-24 23:41:39 UTC (rev 2310) @@ -0,0 +1,204 @@ +/* IndexClient + * + * $Id$ + * + * Created on 4:22:52 PM Oct 12, 2006. + * + * Copyright (C) 2006 Internet Archive. + * + * This file is part of Wayback. + * + * Wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * Wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with Wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.resourceindex.updater; + +import java.io.File; +import java.io.BufferedOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Iterator; +import java.util.logging.Logger; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.InputStreamRequestEntity; +import org.apache.commons.httpclient.methods.PutMethod; +import org.archive.wayback.core.SearchResult; +import org.archive.wayback.resourceindex.cdx.SearchResultToCDXLineAdapter; +import org.archive.wayback.util.AdaptedIterator; +import org.archive.wayback.util.Adapter; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class IndexClient { + private static final Logger LOGGER = Logger.getLogger(IndexClient + .class.getName()); + + private String target = null; + private File tmpDir = null; + + private HttpClient client = new HttpClient(); + + /** + * @param cdx + * @return true if CDX was added to local or remote index + * @throws HttpException + * @throws IOException + */ + public boolean addCDX(File cdx) throws HttpException, IOException { + boolean added = false; + if(target == null) { + throw new IOException("No target set"); + } + String base = cdx.getName(); + if(target.startsWith("http://")) { + String finalUrl = target; + if(target.endsWith("/")) { + finalUrl = target + base; + } else { + finalUrl = target + "/" + base; + } + PutMethod method = new PutMethod(finalUrl); + method.setRequestEntity(new InputStreamRequestEntity( + new FileInputStream(cdx))); + + int statusCode = client.executeMethod(method); + if (statusCode == HttpStatus.SC_OK) { + LOGGER.info("Uploaded cdx " + cdx.getAbsolutePath() + " to " + + finalUrl); + if(!cdx.delete()) { + throw new IOException("FAILED delete " + + cdx.getAbsolutePath()); + } + + added = true; + } else { + throw new IOException("Method failed: " + method.getStatusLine() + + " for URL " + finalUrl + " on file " + + cdx.getAbsolutePath()); + } + + } else { + // assume a local directory: + File toBeMergedDir = new File(target); + if(!toBeMergedDir.exists()) { + toBeMergedDir.mkdirs(); + } + if(!toBeMergedDir.exists()) { + throw new IOException("Target " + target + " does not exist"); + } + if(!toBeMergedDir.isDirectory()) { + throw new IOException("Target " + target + " is not a dir"); + } + if(!toBeMergedDir.canWrite()) { + throw new IOException("Target " + target + " is not writable"); + } + File toBeMergedFile = new File(toBeMergedDir,base); + if(toBeMergedFile.exists()) { + LOGGER.severe("WARNING: "+toBeMergedFile.getAbsolutePath() + + "already exists!"); + } else { + if(cdx.renameTo(toBeMergedFile)) { + LOGGER.info("Queued " + toBeMergedFile.getAbsolutePath() + + " for merging."); + added = true; + } else { + LOGGER.severe("FAILED rename("+cdx.getAbsolutePath()+ + ") to ("+toBeMergedFile.getAbsolutePath()+")"); + } + } + } + return added; + } + + /** + * @param base + * @param itr + * @return true if data was added to local or remote index + * @throws HttpException + * @throws IOException + */ + public boolean addSearchResults(String base, Iterator<SearchResult> itr) + throws HttpException, IOException { + + if(tmpDir == null) { + throw new IOException("No tmpDir argument"); + } + File tmpFile = new File(tmpDir,base); + if(tmpFile.exists()) { + // TODO: is this safe? + if(!tmpFile.delete()) { + throw new IOException("Unable to remove tmp " + + tmpFile.getAbsolutePath()); + } + } + FileOutputStream os = new FileOutputStream(tmpFile); + BufferedOutputStream bos = new BufferedOutputStream(os); + PrintWriter pw = new PrintWriter(bos); + + Adapter<SearchResult,String> adapterSRtoS = + new SearchResultToCDXLineAdapter(); + Iterator<String> itrS = + new AdaptedIterator<SearchResult,String>(itr,adapterSRtoS); + + while(itrS.hasNext()) { + pw.println(itrS.next()); + } + pw.close(); + boolean added = addCDX(tmpFile); + return added; + } + + /** + * @return the target + */ + public String getTarget() { + return target; + } + + /** + * @param target the target to set + */ + public void setTarget(String target) { + this.target = target; + } + + /** + * @return the tmpDir + */ + public String getTmpDir() { + if(tmpDir == null) { + return null; + } + return tmpDir.getAbsolutePath(); + } + + /** + * @param tmpDir the tmpDir to set + */ + public void setTmpDir(String tmpDir) { + this.tmpDir = new File(tmpDir); + if(!this.tmpDir.isDirectory()) { + this.tmpDir.mkdirs(); + } + } +} Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/RemoteSubmitFilter.java (from rev 2302, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/indexer/RemoteSubmitFilter.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/RemoteSubmitFilter.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/updater/RemoteSubmitFilter.java 2008-06-24 23:41:39 UTC (rev 2310) @@ -0,0 +1,187 @@ +/* RemoteSubmitFilter + * + * $Id$ + * + * Created on 3:57:00 PM Oct 12, 2006. + * + * Copyright (C) 2006 Internet Archive. + * + * This file is part of Wayback. + * + * Wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * Wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with Wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.resourceindex.updater; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Properties; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Filter that accepts PUT HTTP requests to insert CDX files into the incoming + * directory for a local BDBIndex. + * + * @author brad + * @version $Date$, $Revision$ + */ +public class RemoteSubmitFilter implements Filter { + + private final static String INCOMING_PATH = "config-tmp.incoming"; + private final static String HTTP_PUT_METHOD = "PUT"; + private File incoming = null; + private File tmpIncoming = null; + + // TODO: get rid of this + @SuppressWarnings("unchecked") + public void init(FilterConfig c) throws ServletException { + + Properties p = new Properties(); + ServletContext sc = c.getServletContext(); + for (Enumeration e = sc.getInitParameterNames(); e.hasMoreElements();) { + String key = (String) e.nextElement(); + p.put(key, sc.getInitParameter(key)); + } + for (Enumeration e = c.getInitParameterNames(); e.hasMoreElements();) { + String key = (String) e.nextElement(); + p.put(key, c.getInitParameter(key)); + } + + String cfgName = INCOMING_PATH; + String incomingPath = p.getProperty(cfgName); + if((incomingPath == null) || incomingPath.length() == 0) { + throw new ServletException("Invalid or missing " + cfgName + + " configuration"); + } + incoming = new File(incomingPath); + tmpIncoming = new File(incoming,"tmp"); + try { + ensureDir(incoming); + ensureDir(tmpIncoming); + } catch (IOException e) { + throw new ServletException(e); + } + } + private void ensureDir(File dir) throws IOException { + if(dir.exists()) { + if(!dir.isDirectory()) { + throw new IOException("Path " + dir.getAbsolutePath() + + "exists but is not a directory."); + } + } else { + if(!dir.mkdirs()) { + throw new IOException("FAILED mkdir " + dir.getAbsolutePath()); + } + } + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, + * javax.servlet.ServletResponse, javax.servlet.FilterChain) + */ + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + if (!handle(request, response)) { + chain.doFilter(request, response); + } + } + /** + * @param request + * @param response + * @return boolean, true unless something went wrong.. + * @throws IOException + * @throws ServletException + */ + protected boolean handle(final ServletRequest request, + final ServletResponse response) throws IOException, + ServletException { + if (!(request instanceof HttpServletRequest)) { + return false; + } + if (!(response instanceof HttpServletResponse)) { + return false; + } + HttpServletRequest httpRequest = (HttpServletRequest) request; + if(httpRequest.getMethod().equals(HTTP_PUT_METHOD)) { + + return handlePut(httpRequest,response); + + } + return false; + } + + protected boolean handlePut(final HttpServletRequest request, + final ServletResponse response) throws IOException, + ServletException { + + String reqURI = request.getRequestURI(); + int lastSlashIdx = reqURI.lastIndexOf("/"); + if (lastSlashIdx == -1) { + return false; + } + String targetFileName = reqURI.substring(lastSlashIdx + 1); + String tmpFileName = targetFileName + ".tmp"; + File tmpFile = new File(tmpIncoming,tmpFileName); + File targetFile = new File(incoming, targetFileName); + + int i; + InputStream input; + input = request.getInputStream(); + BufferedInputStream in = new BufferedInputStream(input); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + FileWriter out = new FileWriter(tmpFile); + + while ((i = reader.read()) != -1) { + out.write(i); + } + + out.close(); + in.close(); + if (!tmpFile.renameTo(targetFile)) { + throw new IOException("Unable to rename " + + tmpFile.getAbsolutePath() + " to " + + targetFile.getAbsolutePath()); + } + + PrintWriter outHTML = response.getWriter(); + outHTML.println("done"); + return true; + } + + /* (non-Javadoc) + * @see javax.servlet.Filter#destroy() + */ + public void destroy() { + // TODO Auto-generated method stub + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |