2005-09-17 jrandom

* Bugfixes in Syndie to handle missing cache files (no data was lost, the
      old posts just didn't show up).
    * Log properly in EepPost
This commit is contained in:
jrandom
2005-09-17 20:08:25 +00:00
committed by zzz
parent d6c3ffde87
commit 20c42a175d
4 changed files with 67 additions and 27 deletions

View File

@ -215,15 +215,19 @@ public class Archive {
private EntryContainer getCachedEntry(File entryDir) { private EntryContainer getCachedEntry(File entryDir) {
try { try {
return new CachedEntry(entryDir); CachedEntry ce = new CachedEntry(entryDir);
if (ce.isValid())
return ce;
return null;
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
File files[] = entryDir.listFiles();
for (int i = 0; i < files.length; i++)
files[i].delete();
entryDir.delete();
return null;
} }
File files[] = entryDir.listFiles();
for (int i = 0; i < files.length; i++)
files[i].delete();
entryDir.delete();
return null;
} }
public EntryContainer getEntry(BlogURI uri) { return getEntry(uri, null); } public EntryContainer getEntry(BlogURI uri) { return getEntry(uri, null); }

View File

@ -28,6 +28,10 @@ class CachedEntry extends EntryContainer {
_attachments = null; _attachments = null;
} }
public boolean isValid() {
return (_entry != null) && (_blog != null);
}
// always available, loaded from meta // always available, loaded from meta
public int getFormat() { return _format; } public int getFormat() { return _format; }
public BlogURI getURI() { return _blog; } public BlogURI getURI() { return _blog; }
@ -70,7 +74,7 @@ class CachedEntry extends EntryContainer {
} }
// now the actual lazy loading code // now the actual lazy loading code
private void importMeta() { private void importMeta() throws IOException {
Properties meta = readProps(new File(_entryDir, EntryExtractor.META)); Properties meta = readProps(new File(_entryDir, EntryExtractor.META));
_format = getInt(meta, "format"); _format = getInt(meta, "format");
_size = getInt(meta, "size"); _size = getInt(meta, "size");
@ -78,8 +82,14 @@ class CachedEntry extends EntryContainer {
} }
private Properties importHeaders() { private Properties importHeaders() {
if (_headers == null) if (_headers == null) {
_headers = readProps(new File(_entryDir, EntryExtractor.HEADERS)); try {
_headers = readProps(new File(_entryDir, EntryExtractor.HEADERS));
} catch (IOException ioe) {
ioe.printStackTrace();
_headers = new Properties();
}
}
return _headers; return _headers;
} }
@ -103,7 +113,7 @@ class CachedEntry extends EntryContainer {
return; return;
} }
private static Properties readProps(File propsFile) { private static Properties readProps(File propsFile) throws IOException {
Properties rv = new Properties(); Properties rv = new Properties();
BufferedReader in = null; BufferedReader in = null;
try { try {
@ -114,8 +124,6 @@ class CachedEntry extends EntryContainer {
if ( (split <= 0) || (split >= line.length()) ) continue; if ( (split <= 0) || (split >= line.length()) ) continue;
rv.setProperty(line.substring(0, split).trim(), line.substring(split+1).trim()); rv.setProperty(line.substring(0, split).trim(), line.substring(split+1).trim());
} }
} catch (IOException ioe) {
ioe.printStackTrace();
} finally { } finally {
if (in != null) try { in.close(); } catch (IOException ioe) {} if (in != null) try { in.close(); } catch (IOException ioe) {}
} }
@ -222,15 +230,20 @@ class CachedEntry extends EntryContainer {
private void importAttachmentHeaders() { private void importAttachmentHeaders() {
if (_attachmentHeaders == null) { if (_attachmentHeaders == null) {
Properties props = readProps(_metaFile); try {
String sz = (String)props.remove(EntryExtractor.ATTACHMENT_DATA_SIZE); Properties props = readProps(_metaFile);
if (sz != null) { String sz = (String)props.remove(EntryExtractor.ATTACHMENT_DATA_SIZE);
try { if (sz != null) {
_dataSize = Integer.parseInt(sz); try {
} catch (NumberFormatException nfe) {} _dataSize = Integer.parseInt(sz);
} catch (NumberFormatException nfe) {}
}
_attachmentHeaders = props;
} catch (IOException ioe) {
ioe.printStackTrace();
_attachmentHeaders = new Properties();
} }
_attachmentHeaders = props;
} }
} }
} }

View File

@ -4,12 +4,24 @@ import java.io.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.util.Log;
/** /**
* Simple helper for uploading files and such via HTTP POST (rfc 1867) * Simple helper for uploading files and such via HTTP POST (rfc 1867)
* *
*/ */
public class EepPost { public class EepPost {
private I2PAppContext _context;
private Log _log;
public EepPost() {
this(I2PAppContext.getGlobalContext());
}
public EepPost(I2PAppContext ctx) {
_context = ctx;
_log = ctx.logManager().getLog(EepPost.class);
}
public static void main(String args[]) { public static void main(String args[]) {
EepPost e = new EepPost(); EepPost e = new EepPost();
Map fields = new HashMap(); Map fields = new HashMap();
@ -53,6 +65,7 @@ public class EepPost {
_onCompletion = onCompletion; _onCompletion = onCompletion;
} }
public void run() { public void run() {
Socket s = null;
try { try {
URL u = new URL(_url); URL u = new URL(_url);
String h = u.getHost(); String h = u.getHost();
@ -68,12 +81,13 @@ public class EepPost {
_proxyPort = p; _proxyPort = p;
} }
Socket s = new Socket(_proxyHost, _proxyPort); s = new Socket(_proxyHost, _proxyPort);
OutputStream out = s.getOutputStream(); OutputStream out = s.getOutputStream();
String sep = getSeparator(); String sep = getSeparator();
long length = calcContentLength(sep, _fields); long length = calcContentLength(sep, _fields);
String header = getHeader(isProxy, path, h, p, sep, length); String header = getHeader(isProxy, path, h, p, sep, length);
System.out.println("Header: \n" + header); if (_log.shouldLog(Log.DEBUG))
_log.debug("Header: \n" + header);
out.write(header.getBytes()); out.write(header.getBytes());
out.flush(); out.flush();
if (false) { if (false) {
@ -82,14 +96,18 @@ public class EepPost {
sendFields(out, sep, _fields); sendFields(out, sep, _fields);
} }
out.flush(); out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); if (_log.shouldLog(Log.DEBUG)) {
String line = null; BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
while ( (line = in.readLine()) != null) String line = null;
System.out.println("recv: [" + line + "]"); while ( (line = in.readLine()) != null) {
_log.debug("recv: [" + line + "]");
}
}
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (s != null) try { s.close(); } catch (IOException ioe) {}
if (_onCompletion != null) if (_onCompletion != null)
_onCompletion.run(); _onCompletion.run();
} }

View File

@ -1,4 +1,9 @@
$Id: history.txt,v 1.253 2005/09/16 16:24:43 jrandom Exp $ $Id: history.txt,v 1.254 2005/09/17 02:31:50 jrandom Exp $
2005-09-17 jrandom
* Bugfixes in Syndie to handle missing cache files (no data was lost, the
old posts just didn't show up).
* Log properly in EepPost
2005-09-17 jrandom 2005-09-17 jrandom
* Added the natively compiled jbigi and patched java service wrapper for * Added the natively compiled jbigi and patched java service wrapper for