1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.javaflow.stores;
18
19 import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
20 import org.apache.commons.jci.stores.ResourceStore;
21
22
23
24
25
26
27 public final class TransformingResourceStore implements ResourceStore {
28
29 private final ResourceStore store;
30 private final ResourceTransformer[] transformers;
31
32 public TransformingResourceStore( final ResourceStore pStore, final ResourceTransformer[] pTransformers) {
33 store = pStore;
34 transformers = pTransformers;
35 }
36
37 public byte[] read(String resourceName) {
38 return store.read(resourceName);
39 }
40 public void remove(String resourceName) {
41 store.remove(resourceName);
42 }
43 public void write(String resourceName, byte[] resourceData) {
44 byte[] out = resourceData;
45
46
47
48 byte[] in = resourceData;
49
50 for(int i=0; i<transformers.length; i++) {
51 out = transformers[i].transform(in);
52 in = out;
53 }
54
55
56 store.write(resourceName, out);
57 }
58
59 public String toString() {
60 return store.toString();
61 }
62 }