자바 소스 분석좀도와주세요
파랑
자바 에디터에 한부분 코드입니다.
부탁드립니다.
public class DocumentEditorApp extends SingleFrameApplication {
@Override protected void startup() {
show(new DocumentEditorView(this));
}
}
public static DocumentEditorApp getApplication() {
return Application.getInstance(DocumentEditorApp.class);
}
public static void main(String[] args) {
launch(DocumentEditorApp.class, args);
}
static class SaveTextFileTask extends TaskVoid, Void {
private final File file;
private final String text;
SaveTextFileTask(Application app, File file, String text) {
super(app);
this.file = file;
this.text = text;
}
public final File getFile() {
return file;
}
public final String getText() {
return text;
}
private void renameFile(File oldFile, File newFile) throws IOException {
if (!oldFile.renameTo(newFile)) {
String fmt = file rename failed: %s = %s;
throw new IOException(String.format(fmt, oldFile, newFile));
}
}
protected Void doInBackground() throws IOException {
String absPath = file.getAbsolutePath();
File tmpFile = new File(absPath + .tmp);
tmpFile.createNewFile();
tmpFile.deleteOnExit();
File backupFile = new File(absPath + .bak);
BufferedWriter out = null;
int fileLength = text.length();
int blockSize = Math.max(1024, 1 + ((fileLength - 1) / 100));
try {
out = new BufferedWriter(new FileWriter(tmpFile));
int offset = 0;
while (!isCancelled() && (offset fileLength)) {
int length = Math.min(blockSize, fileLength - offset);
out.write(text, offset, length);
offset += blockSize;
setProgress(Math.min(offset, fileLength), 0, fileLength);
}
} finally {
if (out != null) {
out.close();
}
}
if (!isCancelled()) {
backupFile.delete();
if (file.exists()) {
renameFile(file, backupFile);
}
renameFile(tmpFile, file);
} else {
tmpFile.delete();
}
return null;
}
-
핑크빛애교
코드 해석은 최대한 해보시고 모르는 부분을 물어보세요~