- Timestamp:
- 06/26/19 16:02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/io/EncryptedExpReader.java
r1413 r1414 14 14 import java.util.Base64; 15 15 import java.util.List; 16 import java.util.function.BiConsumer; 16 17 import java.util.function.Predicate; 17 18 … … 30 31 import org.expeditee.gui.FrameIO; 31 32 import org.expeditee.io.Conversion; 33 import org.expeditee.io.DefaultFrameWriter; 32 34 import org.expeditee.io.ExpReader; 33 35 import org.expeditee.items.Item; … … 122 124 } 123 125 124 @Override 126 // @Override 127 // protected String readTheItems(Frame newFrame, List<DelayedAction> delayedActions) throws IOException { 128 // String next = null; 129 // Item currentItem = null; 130 // 131 // Predicate<String> endOfSection = s -> s.equals(EncryptedExpWriter.TERMINATOR + "") || s.equals(EncryptedExpWriter.TERMINATOR_WITH_CONTINUATION); 132 // while (_reader.ready() && !endOfSection.test(next = _reader.readLine())) { 133 // if (!isValidLine(next)) { 134 // continue; 135 // } 136 // 137 // String tag = getTagEnc(next); 138 // if (next.startsWith(DefaultFrameWriter.TYPE_AND_ID_STR + " ")) { 139 // currentItem = newItem(next); 140 // _linePoints.put(currentItem.getID(), currentItem); 141 // newFrame.addItem(currentItem); 142 // currentItem.setEncryptionDetailForTag(tag + "", EncryptionDetail.UnencryptedOnSave); 143 // } else if (next.startsWith("SurrogateFor")) { 144 // int parentID = Integer.parseInt(next.split(" ")[1]); 145 // newFrame.getItemWithID(parentID).addToSurrogates(currentItem); 146 // newFrame.addToSurrogates(currentItem); 147 // } else if (currentItem != null && actionShouldBeDelayed(tag.charAt(0))) { 148 // delayedActions.add(new DelayedAction(currentItem, next)); 149 // } else if (currentItem != null) { 150 // processBodyLine(currentItem, next); 151 // } else { 152 // System.err.println("Error while reading in frame (ExpReader): Found body line but no current item to apply it to."); 153 // } 154 // } 155 // 156 // if (next.equals(EncryptedExpWriter.TERMINATOR_WITH_CONTINUATION)) { 157 // next = readTheItems(newFrame, delayedActions); 158 // } 159 // 160 // return next; 161 // } 162 125 163 protected String readTheItems(Frame newFrame, List<DelayedAction> delayedActions) throws IOException { 164 // Read the primary item. 165 BiConsumer<Item, String> addToBody = (item, line) -> newFrame.addItem(item); 166 String next = readLineAfterLine(false, addToBody, delayedActions); 167 168 // Read the surrogate items. 169 if (next.equals(EncryptedExpWriter.TERMINATOR_WITH_CONTINUATION)) { 170 BiConsumer<Item, String> addToSurrogates = (item, line) -> { 171 int parentID = Integer.parseInt(line.split(" ")[1]); 172 newFrame.getItemWithID(parentID).addToSurrogates(item); 173 newFrame.addToSurrogates(item); 174 }; 175 next = readLineAfterLine(true, addToSurrogates, delayedActions); 176 } 177 return next; 178 } 179 180 private String readLineAfterLine(boolean isSurrogate, BiConsumer<Item, String> storeResult, List<DelayedAction> delayedActions) throws IOException { 126 181 String next = null; 127 182 Item currentItem = null; 128 183 129 Predicate<String> endOfSection = s -> s.equals( "Z") || s.equals("Z...");184 Predicate<String> endOfSection = s -> s.equals(EncryptedExpWriter.TERMINATOR + "") || s.equals(EncryptedExpWriter.TERMINATOR_WITH_CONTINUATION); 130 185 while (_reader.ready() && !endOfSection.test(next = _reader.readLine())) { 131 186 if (!isValidLine(next)) { … … 134 189 135 190 String tag = getTagEnc(next); 136 if (next.startsWith( "S")) {191 if (next.startsWith(DefaultFrameWriter.TYPE_AND_ID_STR + " ")) { 137 192 currentItem = newItem(next); 138 193 _linePoints.put(currentItem.getID(), currentItem); 139 newFrame.addItem(currentItem); 194 if (!isSurrogate) { 195 storeResult.accept(currentItem, next); 196 } 140 197 currentItem.setEncryptionDetailForTag(tag + "", EncryptionDetail.UnencryptedOnSave); 141 198 } else if (next.startsWith("SurrogateFor")) { 142 int parentID = Integer.parseInt(next.split(" ")[1]); 143 newFrame.getItemWithID(parentID).addToSurrogates(currentItem); 199 if (isSurrogate) { 200 storeResult.accept(currentItem, next); 201 } 144 202 } else if (currentItem != null && actionShouldBeDelayed(tag.charAt(0))) { 145 203 delayedActions.add(new DelayedAction(currentItem, next)); … … 151 209 } 152 210 153 if (next.equals(EncryptedExpWriter.SURROGATE_TERMINATOR)) {154 next = readTheItems(newFrame, delayedActions);155 }156 157 211 return next; 158 212 } 213 214 // private String readLineAfterLine(Consumer<Item> storeResult, List<DelayedAction> delayedActions) throws IOException { 215 // String next = null; 216 // Item currentItem = null; 217 // 218 // Predicate<String> endOfSection = s -> { 219 // return s.equals(EncryptedExpWriter.TERMINATOR + "") || s.equals(EncryptedExpWriter.TERMINATOR_WITH_CONTINUATION); 220 // }; 221 // while (_reader.ready() && !endOfSection.test(next = _reader.readLine())) { 222 // if (!isValidLine(next)) { 223 // continue; 224 // } 225 // 226 // String tag = getTagEnc(next); 227 // if (next.startsWith(DefaultFrameWriter.TYPE_AND_ID_STR + " ")) { 228 // currentItem = newItem(next); 229 // _linePoints.put(currentItem.getID(), currentItem); 230 // currentItem.setEncryptionDetailForTag(tag + "", EncryptionDetail.UnencryptedOnSave); 231 // storeResult.accept(currentItem); 232 // } else if (next.startsWith("SurrogateFor")) { 233 // int parentID = Integer.parseInt(next.split(" ")[1]); 234 // newFrame.getItemWithID(parentID).addToSurrogates(currentItem); 235 // new Delayed 236 // } 237 // } 238 // 239 // return next; 240 // } 159 241 160 242 @Override
Note:
See TracChangeset
for help on using the changeset viewer.