Changeset 229
- Timestamp:
- 11/11/02 18:12:17 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/j/mail/News.java
r93 r229 3 3 * 4 4 * Copyright (C) 2000-2002 Peter Graves 5 * $Id: News.java,v 1. 2 2002-10-11 01:42:37 piso Exp $5 * $Id: News.java,v 1.3 2002-11-11 18:12:17 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 73 73 public void run() 74 74 { 75 File file = File.getInstance(newsDir, session.getHost()); 76 if (newsDir.isDirectory()) { 77 if (file.isFile()) { 78 try { 79 InputStream in = file.getInputStream(); 80 if (in != null) { 81 load(in, null); 82 in.close(); 83 } 84 } 85 catch (IOException e) { 86 Log.error(e); 87 } 88 } 89 } else 90 newsDir.mkdirs(); 91 if (getFirstLine() == null) { 92 if (session.connect()) { 93 if (session.writeLine("LIST")) { 94 String response = session.readLine(); 95 if (response.startsWith("215")) { 96 session.setEcho(false); 97 int count = 0; 98 progressNotifier.progressStart(); 99 while (true) { 100 String s = session.readLine(); 101 if (s == null) 102 break; 103 if (s.equals(".")) 104 break; 105 int index = s.indexOf(' '); 106 if (index >= 0) 107 appendLine(s.substring(0, index)); 108 else 109 appendLine(s); 110 ++count; 111 progressNotifier.progress(String.valueOf(count)); 112 } 113 if (newsDir.isDirectory()) { 114 try { 115 BufferedWriter writer = new BufferedWriter( 116 new OutputStreamWriter(file.getOutputStream())); 117 for (Line line = getFirstLine(); line != null; line = line.next()) { 118 writer.write(line.getText()); 119 writer.write('\n'); 120 } 121 writer.flush(); 122 writer.close(); 123 } 124 catch (IOException e) { 125 Log.error(e); 126 } 127 } 128 progressNotifier.progressStop(); 129 session.setEcho(NntpSession.DEFAULT_ECHO); 130 } 131 } 132 session.disconnect(); 133 } 75 try { 76 lockWrite(); 134 77 } 135 renumber(); 78 catch (InterruptedException e) { 79 Log.error(e); 80 return; 81 } 82 try { 83 _load(); 84 } 85 finally { 86 unlockWrite(); 87 } 136 88 SwingUtilities.invokeLater(updateDisplayRunnable); 137 89 } 138 90 }; 91 92 private void _load() 93 { 94 File file = File.getInstance(newsDir, session.getHost()); 95 if (newsDir.isDirectory()) { 96 if (file.isFile()) { 97 try { 98 InputStream in = file.getInputStream(); 99 if (in != null) { 100 load(in, null); 101 in.close(); 102 } 103 } 104 catch (IOException e) { 105 Log.error(e); 106 } 107 } 108 } else 109 newsDir.mkdirs(); 110 if (getFirstLine() == null) { 111 if (session.connect()) { 112 if (session.writeLine("LIST")) { 113 String response = session.readLine(); 114 if (response.startsWith("215")) { 115 session.setEcho(false); 116 int count = 0; 117 progressNotifier.progressStart(); 118 while (true) { 119 String s = session.readLine(); 120 if (s == null) 121 break; 122 if (s.equals(".")) 123 break; 124 int index = s.indexOf(' '); 125 if (index >= 0) 126 appendLine(s.substring(0, index)); 127 else 128 appendLine(s); 129 ++count; 130 progressNotifier.progress(String.valueOf(count)); 131 } 132 if (newsDir.isDirectory()) { 133 try { 134 BufferedWriter writer = new BufferedWriter( 135 new OutputStreamWriter(file.getOutputStream())); 136 for (Line line = getFirstLine(); line != null; line = line.next()) { 137 writer.write(line.getText()); 138 writer.write('\n'); 139 } 140 writer.flush(); 141 writer.close(); 142 } 143 catch (IOException e) { 144 Log.error(e); 145 } 146 } 147 progressNotifier.progressStop(); 148 session.setEcho(NntpSession.DEFAULT_ECHO); 149 } 150 } 151 session.disconnect(); 152 } 153 } 154 renumber(); 155 } 139 156 140 157 private Runnable updateDisplayRunnable = new Runnable() {
Note: See TracChangeset
for help on using the changeset viewer.