24 |
import gzz.media.MediaInputStream; |
import gzz.media.MediaInputStream; |
25 |
import gzz.media.MediaOutputStream; |
import gzz.media.MediaOutputStream; |
26 |
|
|
27 |
|
import gzz.util.CopyUtil; |
28 |
import gzz.util.Filer; |
import gzz.util.Filer; |
29 |
import gzz.util.HeaderUtil; |
import gzz.util.HeaderUtil; |
30 |
import gzz.util.Version; |
import gzz.util.Version; |
34 |
import java.util.*; |
import java.util.*; |
35 |
|
|
36 |
public class MediaserverFiler implements Filer { |
public class MediaserverFiler implements Filer { |
37 |
|
public static boolean dbg = false; |
38 |
|
private static void pa(String s) { System.out.println(s); } |
39 |
|
|
40 |
public static final String versionContentType = "application/x-GZZ2-version"; |
public static final String versionContentType = "application/x-GZZ2-version"; |
41 |
public static final String diffContentType = "application/x-GZZ2-msfiler-diff"; |
public static final String diffContentType = "application/x-GZZ2-msfiler-diff"; |
115 |
Version.Diff diff = fmt.readDiff(is); |
Version.Diff diff = fmt.readDiff(is); |
116 |
Version v = diff.applyTo(from); |
Version v = diff.applyTo(from); |
117 |
|
|
118 |
if(!id.equals(getVersionId(v, headerTo))) |
if(!id.equals(getVersionId(v, headerTo))) { |
119 |
|
if(dbg) { |
120 |
|
pa("============= DIFF ==============="); |
121 |
|
pa(new String(CopyUtil.readBytes(diffBlock.getInputStream()))); |
122 |
|
pa("=================================="); |
123 |
|
pa("Diff: "+diff); |
124 |
|
pa(""); |
125 |
|
pa("From: "+from); |
126 |
|
pa(""); |
127 |
|
pa("Gives: "+v); |
128 |
|
pa("============== BAD ==============="); |
129 |
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
130 |
|
fmt.writeVersion(bos, v); |
131 |
|
pa(new String(bos.toByteArray())); |
132 |
|
pa("=================================="); |
133 |
|
} |
134 |
throw new IOException("Version doesn't match: "+v+"\n"+ |
throw new IOException("Version doesn't match: "+v+"\n"+ |
135 |
"Wanted id = "+id+"\n"+ |
"Wanted id = "+id+"\n"+ |
136 |
"Regenerated id = "+getVersionId(v, headerTo)+"\n"+ |
"Regenerated id = "+getVersionId(v, headerTo)+"\n"+ |
137 |
"Using diff: "+diffId+"\n"); |
"Using diff: "+diffId+"\n"); |
138 |
|
} |
139 |
|
|
140 |
if(hdr != null) |
if(hdr != null) |
141 |
hdr[0] = headerTo; |
hdr[0] = headerTo; |
214 |
fmt.writeVersion(bos, v); |
fmt.writeVersion(bos, v); |
215 |
ms.addDatum(bos.toByteArray(), |
ms.addDatum(bos.toByteArray(), |
216 |
versionContentType, current); |
versionContentType, current); |
217 |
|
if(dbg) { |
218 |
|
pa("============ CORRECT ============="); |
219 |
|
pa(new String(bos.toByteArray())); |
220 |
|
pa("=================================="); |
221 |
|
} |
222 |
t.printStackTrace(); |
t.printStackTrace(); |
223 |
throw new Error("Problem with re-loading: "+t); |
throw new Error("Problem with re-loading: "+t); |
224 |
} |
} |