if (ret==null) ret = (String)head.get(s.toLowerCase());
return ret;
}
+ public void remove(String k) { put(k, null); }
public void put(String k, String v) {
Stream stream = getStream();
StringBuffer all = new StringBuffer();
int lines = 0;
- boolean good = false;
String key = null;
for(String s = stream.readln(); s != null && !s.equals(""); s = stream.readln()) {
- if (Character.isSpace(s.charAt(0))) { all.append(s); all.append("\r\n"); lines++; continue; }
- if (s.indexOf(':') == -1) throw new Malformed("Header line does not contain colon: " + s);
- key = s.substring(0, s.indexOf(':')).toLowerCase();
- lines++;
+ if (!Character.isSpace(s.charAt(0))) {
+ if (s.indexOf(':') == -1) throw new Malformed("Header line does not contain colon: " + s);
+ key = s.substring(0, s.indexOf(':')).toLowerCase();
+ }
if (key.toLowerCase().equals(k.toLowerCase())) {
- good = true;
- all.append(k + ": " + v + "\r\n");
+ if (v != null) { all.append(k + ": " + v + "\r\n"); lines++; v = null; }
continue;
}
all.append(s);
all.append("\r\n");
+ lines++;
}
- if (!good) {
+ if (v != null) {
lines++;
all.append(k + ": " + v + "\r\n");
}