Minor reformatting.

This commit is contained in:
Jonathan Bernard 2013-07-19 18:47:45 -05:00
parent b56a708a09
commit 988ed2bb51

View File

@ -26,8 +26,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
ReadMark, ReadMark,
StartNotes, StartNotes,
ReadNotes, ReadNotes,
EndMarker EndMarker };
};
private InputStream in; private InputStream in;
@ -39,18 +38,15 @@ public class StreamBasedTimelineSource extends TimelineSource {
super(null); super(null);
this.in = inStream; this.in = inStream;
this.out = outStream; this.out = outStream;
this.comments = new ByteArrayOutputStream(); this.comments = new ByteArrayOutputStream(); }
}
/** {@inheritDoc } */ /** {@inheritDoc } */
public Timeline read() throws IOException { public Timeline read() throws IOException {
return readFromStream(in, comments); return readFromStream(in, comments); }
}
/** {@inheritDoc } */ /** {@inheritDoc } */
public void persist(Timeline t) throws IOException { public void persist(Timeline t) throws IOException {
writeToStream(out, t); writeToStream(out, t); }
}
public void authenticate() throws AuthenticationException { } public void authenticate() throws AuthenticationException { }
public boolean isAuthenticated() { return true; } public boolean isAuthenticated() { return true; }
@ -60,9 +56,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
* @return a <code>byte[]</code> representing the portions of the file * @return a <code>byte[]</code> representing the portions of the file
* which were comments. * which were comments.
*/ */
public byte[] getCommentBytes() { public byte[] getCommentBytes() { return comments.toByteArray(); }
return comments.toByteArray();
}
/** /**
* Write the a representation of the timeline to a stream. This method * Write the a representation of the timeline to a stream. This method
@ -89,8 +83,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
for (i = 0; (i + lineWrap) < mark.length(); i+=lineWrap) for (i = 0; (i + lineWrap) < mark.length(); i+=lineWrap)
out.write(mark.substring(i, i+lineWrap) + "\\\n"); out.write(mark.substring(i, i+lineWrap) + "\\\n");
if (i < mark.length()) if (i < mark.length())
out.write(mark.substring(i, mark.length()) + "\n"); out.write(mark.substring(i, mark.length()) + "\n"); }
}
// write notes // write notes
String notes = tm.getNotes().replace('\n', '\u0000'); String notes = tm.getNotes().replace('\n', '\u0000');
@ -101,12 +94,9 @@ public class StreamBasedTimelineSource extends TimelineSource {
for (i = 0; (i + lineWrap) < notes.length(); i+=lineWrap) for (i = 0; (i + lineWrap) < notes.length(); i+=lineWrap)
out.write(notes.substring(i, i+lineWrap) + "\\\n"); out.write(notes.substring(i, i+lineWrap) + "\\\n");
if (i < notes.length()) if (i < notes.length())
out.write(notes.substring(i, notes.length()) + "\n"); out.write(notes.substring(i, notes.length()) + "\n"); }
} out.write("\n"); }
out.write("\n"); out.flush(); }
}
out.flush();
}
/** /**
@ -118,8 +108,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
*/ */
public static Timeline readFromStream(InputStream stream) public static Timeline readFromStream(InputStream stream)
throws IOException { throws IOException {
return readFromStream(stream, null); return readFromStream(stream, null); }
}
/** /**
* Create a <b>Timeline</b> instance from a given stream. * Create a <b>Timeline</b> instance from a given stream.
@ -151,8 +140,8 @@ public class StreamBasedTimelineSource extends TimelineSource {
// line is a comment // line is a comment
if (line.startsWith("#")) { if (line.startsWith("#")) {
if (commentsWriter != null) commentsWriter.println(line); if (commentsWriter != null) commentsWriter.println(line);
continue; // don't parse this line as part of the timeline // don't parse this line as part of the timeline
} continue; }
switch (readingState) { switch (readingState) {
@ -161,8 +150,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
catch (ParseException pe) { catch (ParseException pe) {
throw new IOException("Error parsing timeline file at line " throw new IOException("Error parsing timeline file at line "
+ lineNumber + ": expected a new marker date but could not parse" + lineNumber + ": expected a new marker date but could not parse"
+ " the date. Error: " + pe.getLocalizedMessage()); + " the date. Error: " + pe.getLocalizedMessage()); }
}
readingState = ReadingState.StartMark; readingState = ReadingState.StartMark;
break; break;
@ -172,8 +160,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
case ReadMark: case ReadMark:
if (line.endsWith("\\")) { if (line.endsWith("\\")) {
readingState = ReadingState.ReadMark; readingState = ReadingState.ReadMark;
line = line.substring(0, line.length() - 1); line = line.substring(0, line.length() - 1); }
}
else readingState = ReadingState.StartNotes; else readingState = ReadingState.StartNotes;
mark.append(line); mark.append(line);
break; break;
@ -184,8 +171,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
case ReadNotes: case ReadNotes:
if (line.endsWith("\\")) { if (line.endsWith("\\")) {
readingState = ReadingState.ReadNotes; readingState = ReadingState.ReadNotes;
line = line.substring(0, line.length() - 1); line = line.substring(0, line.length() - 1); }
}
else readingState = ReadingState.EndMarker; else readingState = ReadingState.EndMarker;
notes.append(line); notes.append(line);
break; break;
@ -194,10 +180,7 @@ public class StreamBasedTimelineSource extends TimelineSource {
String sMark = mark.toString().replace('\u0000', '\n'); String sMark = mark.toString().replace('\u0000', '\n');
String sNotes = notes.toString().replace('\u0000', '\n'); String sNotes = notes.toString().replace('\u0000', '\n');
timeline.addMarker(d, sMark, sNotes); timeline.addMarker(d, sMark, sNotes);
readingState = ReadingState.NewMarker; readingState = ReadingState.NewMarker; } }
}
}
return timeline; return timeline; }
}
} }