*** empty log message ***
[cyberduck.git] / source / ch / cyberduck / Attic / connection / Log.java
blobf82552ec87902403a23e9c10fe2add974191c672
1 package ch.cyberduck.connection;
3 /*
4 * ch.cyberduck.connection.Log.java
5 * Cyberduck
7 * $Header$
8 * $Revision$
9 * $Date$
11 * Copyright (c) 2003 David Kocher. All rights reserved.
12 * http://icu.unizh.ch/~dkocher/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * Bug fixes, suggestions and comments should be sent to:
25 * dkocher@cyberduck.ch
28 import java.io.*;
30 import ch.cyberduck.Cyberduck;
31 import ch.cyberduck.Preferences;
33 /**
34 * I am the logger of a connection.
35 * @version $Id$
37 public class Log {
38 StringBuffer buffer;
40 public Log () {
41 Cyberduck.DEBUG("[Log] new Log()");
42 buffer = new StringBuffer();
45 public void append(String text) {
46 // Cyberduck.DEBUG("[Log] append(" + text + ")");
47 buffer.append(text + Cyberduck.SEPARATOR);
50 public void save() {
51 Cyberduck.DEBUG("[Log] save()");
52 FileWriter fw = null;
53 BufferedWriter bw = null;
54 try {
55 File prefFile = new File(Cyberduck.PREFS_DIRECTORY, Preferences.instance().getProperty("connection.log.file"));
56 bw = new BufferedWriter(fw = new FileWriter(prefFile.toString(), true));
57 String logtext = buffer.toString();
58 if (logtext != null) {
59 // bw.write("////////////////////////////////////////////////");
60 bw.newLine();
61 // bw.write(Cyberduck.SEPARATOR + logtext + Cyberduck.SEPARATOR);
62 bw.write(logtext);
63 bw.newLine();
64 Cyberduck.DEBUG("[Log] " + logtext);
66 bw.flush();
68 catch (IOException e) {
69 System.out.println("Error: " + e.getMessage());
70 e.printStackTrace();
72 finally {
73 try {
74 if(fw != null)
75 fw.close();
76 if(bw != null)
77 bw.close();
79 catch(IOException close) {
80 System.err.println("[Log] Error: " + close.getMessage());
81 close.printStackTrace();
86 public static String open() {
87 Cyberduck.DEBUG("[Log] open()");
88 StringBuffer logtext = new StringBuffer();
89 File path = new File(Cyberduck.PREFS_DIRECTORY, Preferences.instance().getProperty("connection.log.file"));
90 if(path.exists()) {
91 try {
92 FileReader fr = new FileReader(path);
93 BufferedReader br = new BufferedReader(fr);
94 boolean eof = false;
95 while(!eof) {
96 String line = br.readLine();
97 if (line == null) {
98 eof = true;
100 else {
101 logtext.append(line + Cyberduck.SEPARATOR);
105 catch (IOException e) {
106 System.err.println("[Log] Could not open log file." + e.getMessage());
109 return logtext.toString();
112 public static void delete() {
113 Cyberduck.DEBUG("[Log] delete()");
114 try {
115 File path = new File(Cyberduck.PREFS_DIRECTORY, Preferences.instance().getProperty("connection.log.file"));
116 if (path.exists())
117 path.delete();
119 catch(SecurityException e) {
120 System.err.println("[Log] Could not delete log file: " + e.getMessage());