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.warning("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;
	}
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 { 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 . warning ( "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 cdx
@return true if CDX was added to local or remote index
@throws HttpException
@throws IOException