FileDocCategorySizeDatePackage
SafeSave.javaAPI DocGlassfish v2 API3251Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.misc

SafeSave

public final class SafeSave extends Object
Utilities for performing a safe save involving a temp file

Fields Summary
Constructors Summary
private SafeSave()

Methods Summary
private static java.io.FileformTempName(java.lang.String baseName)

		return( new File ( baseName + System.currentTimeMillis() + ".temp" ) );
	
public static java.io.FilegetTempFile(java.io.File baseFile)
Reads a line, outputting an optional prompt first. If the prompt is null then no prompt is printed.

		File	tempFile	= null;
		
		while ( (tempFile = formTempName( baseFile.toString() ) ).exists() )
		{
		}
		
		return( tempFile );
	
public static voidreplaceWithNew(java.io.File origFile, java.io.File newFile)
Replace the original file with the new file in a manner which will not result in data loss, with the worst risk being that the original file will be left with a different name.

		final File	origTemp	= getTempFile( origFile );
		
		origFile.renameTo( origTemp );
		newFile.renameTo( origFile );
		origTemp.delete();