1 |
//(c):Benja Fallenstein |
//(c):Benja Fallenstein |
2 |
package gzz.storm.util; |
package gzz.storm.util; |
3 |
import gzz.util.*; |
import gzz.util.*; |
4 |
|
import java.io.*; |
5 |
import java.util.*; |
import java.util.*; |
6 |
|
|
7 |
/** A simple mock implementation of Version, for testing. |
/** A simple mock implementation of Version, for testing. |
62 |
return 138789^diff; |
return 138789^diff; |
63 |
} |
} |
64 |
} |
} |
65 |
|
|
66 |
|
/** A version format for use with TestVersions and TestVersion.Diffs. |
67 |
|
* Stores the value/difference as an ASCII number. |
68 |
|
*/ |
69 |
|
public static class Format implements VersionFormat { |
70 |
|
public void writeVersion(OutputStream out, Version v) throws IOException { |
71 |
|
String s = ""+((TestVersion)v).value; |
72 |
|
out.write(s.getBytes("US-ASCII")); |
73 |
|
} |
74 |
|
public void writeDiff(OutputStream out, Version.Diff d) throws IOException { |
75 |
|
String s = ""+((Diff)d).diff; |
76 |
|
out.write(s.getBytes("US-ASCII")); |
77 |
|
} |
78 |
|
|
79 |
|
public Version readVersion(InputStream in) throws IOException { |
80 |
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
81 |
|
CopyUtil.copy(in, bos); |
82 |
|
String s = new String(bos.toByteArray(), "US-ASCII"); |
83 |
|
return new TestVersion(Integer.parseInt(s)); |
84 |
|
} |
85 |
|
public Version.Diff readDiff(InputStream in) throws IOException { |
86 |
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
87 |
|
CopyUtil.copy(in, bos); |
88 |
|
String s = new String(bos.toByteArray(), "US-ASCII"); |
89 |
|
return new Diff(Integer.parseInt(s)); |
90 |
|
} |
91 |
|
} |
92 |
} |
} |