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:
@ -215,15 +215,19 @@ public class Archive {
|
||||
|
||||
private EntryContainer getCachedEntry(File entryDir) {
|
||||
try {
|
||||
return new CachedEntry(entryDir);
|
||||
CachedEntry ce = new CachedEntry(entryDir);
|
||||
if (ce.isValid())
|
||||
return ce;
|
||||
return null;
|
||||
} catch (IOException ioe) {
|
||||
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); }
|
||||
|
@ -28,6 +28,10 @@ class CachedEntry extends EntryContainer {
|
||||
_attachments = null;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return (_entry != null) && (_blog != null);
|
||||
}
|
||||
|
||||
// always available, loaded from meta
|
||||
public int getFormat() { return _format; }
|
||||
public BlogURI getURI() { return _blog; }
|
||||
@ -70,7 +74,7 @@ class CachedEntry extends EntryContainer {
|
||||
}
|
||||
|
||||
// now the actual lazy loading code
|
||||
private void importMeta() {
|
||||
private void importMeta() throws IOException {
|
||||
Properties meta = readProps(new File(_entryDir, EntryExtractor.META));
|
||||
_format = getInt(meta, "format");
|
||||
_size = getInt(meta, "size");
|
||||
@ -78,8 +82,14 @@ class CachedEntry extends EntryContainer {
|
||||
}
|
||||
|
||||
private Properties importHeaders() {
|
||||
if (_headers == null)
|
||||
_headers = readProps(new File(_entryDir, EntryExtractor.HEADERS));
|
||||
if (_headers == null) {
|
||||
try {
|
||||
_headers = readProps(new File(_entryDir, EntryExtractor.HEADERS));
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
_headers = new Properties();
|
||||
}
|
||||
}
|
||||
return _headers;
|
||||
}
|
||||
|
||||
@ -103,7 +113,7 @@ class CachedEntry extends EntryContainer {
|
||||
return;
|
||||
}
|
||||
|
||||
private static Properties readProps(File propsFile) {
|
||||
private static Properties readProps(File propsFile) throws IOException {
|
||||
Properties rv = new Properties();
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
@ -114,8 +124,6 @@ class CachedEntry extends EntryContainer {
|
||||
if ( (split <= 0) || (split >= line.length()) ) continue;
|
||||
rv.setProperty(line.substring(0, split).trim(), line.substring(split+1).trim());
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
@ -222,15 +230,20 @@ class CachedEntry extends EntryContainer {
|
||||
|
||||
private void importAttachmentHeaders() {
|
||||
if (_attachmentHeaders == null) {
|
||||
Properties props = readProps(_metaFile);
|
||||
String sz = (String)props.remove(EntryExtractor.ATTACHMENT_DATA_SIZE);
|
||||
if (sz != null) {
|
||||
try {
|
||||
_dataSize = Integer.parseInt(sz);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
try {
|
||||
Properties props = readProps(_metaFile);
|
||||
String sz = (String)props.remove(EntryExtractor.ATTACHMENT_DATA_SIZE);
|
||||
if (sz != null) {
|
||||
try {
|
||||
_dataSize = Integer.parseInt(sz);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
|
||||
_attachmentHeaders = props;
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
_attachmentHeaders = new Properties();
|
||||
}
|
||||
|
||||
_attachmentHeaders = props;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,24 @@ import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Simple helper for uploading files and such via HTTP POST (rfc 1867)
|
||||
*
|
||||
*/
|
||||
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[]) {
|
||||
EepPost e = new EepPost();
|
||||
Map fields = new HashMap();
|
||||
@ -53,6 +65,7 @@ public class EepPost {
|
||||
_onCompletion = onCompletion;
|
||||
}
|
||||
public void run() {
|
||||
Socket s = null;
|
||||
try {
|
||||
URL u = new URL(_url);
|
||||
String h = u.getHost();
|
||||
@ -68,12 +81,13 @@ public class EepPost {
|
||||
_proxyPort = p;
|
||||
}
|
||||
|
||||
Socket s = new Socket(_proxyHost, _proxyPort);
|
||||
s = new Socket(_proxyHost, _proxyPort);
|
||||
OutputStream out = s.getOutputStream();
|
||||
String sep = getSeparator();
|
||||
long length = calcContentLength(sep, _fields);
|
||||
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.flush();
|
||||
if (false) {
|
||||
@ -82,14 +96,18 @@ public class EepPost {
|
||||
sendFields(out, sep, _fields);
|
||||
}
|
||||
out.flush();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
|
||||
String line = null;
|
||||
while ( (line = in.readLine()) != null)
|
||||
System.out.println("recv: [" + line + "]");
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
|
||||
String line = null;
|
||||
while ( (line = in.readLine()) != null) {
|
||||
_log.debug("recv: [" + line + "]");
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (s != null) try { s.close(); } catch (IOException ioe) {}
|
||||
if (_onCompletion != null)
|
||||
_onCompletion.run();
|
||||
}
|
||||
|
@ -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
|
||||
* Added the natively compiled jbigi and patched java service wrapper for
|
||||
|
Reference in New Issue
Block a user