Reads the contents of the given PlayerCharacter from a stream author: Thomas Behr 11-03-02 @param pcToBeRead the PlayerCharacter to store the read data @param in the stream to be read from @param validate
(PlayerCharacter pcToBeRead, InputStream in, final boolean validate)
| 125 | * @param validate |
| 126 | */ |
| 127 | @Override |
| 128 | public void read(PlayerCharacter pcToBeRead, InputStream in, final boolean validate) |
| 129 | { |
| 130 | warnings.clear(); |
| 131 | |
| 132 | final List<String> lines = readPcgLines(in); |
| 133 | boolean isPCGVersion2 = isPCGCersion2(lines); |
| 134 | |
| 135 | pcToBeRead.setImporting(true); |
| 136 | |
| 137 | final String[] pcgLines = lines.toArray(new String[0]); |
| 138 | if (isPCGVersion2) |
| 139 | { |
| 140 | final PCGParser parser = new PCGVer2Parser(pcToBeRead); |
| 141 | try |
| 142 | { |
| 143 | // parse it all |
| 144 | parser.parsePCG(pcgLines); |
| 145 | } catch (PCGParseException pcgex) |
| 146 | { |
| 147 | Logging.errorPrint("Error loading character: " + pcgex.getMessage() + "\n Method " + pcgex.getMethod() |
| 148 | + " was unable to parse line " + pcgex.getLine()); |
| 149 | errors.add(LanguageBundle.getFormattedString("in_pcgIoErrorReport", pcgex.getMessage())); //$NON-NLS-1$ |
| 150 | } |
| 151 | |
| 152 | warnings.addAll(parser.getWarnings()); |
| 153 | |
| 154 | // we are now all done with the import parsing, so turn off |
| 155 | // the Importing flag and then do some sanity checks |
| 156 | pcToBeRead.setImporting(false); |
| 157 | |
| 158 | try |
| 159 | { |
| 160 | sanityChecks(pcToBeRead, parser); |
| 161 | } catch (NumberFormatException ex) |
| 162 | { |
| 163 | errors.add(ex.getMessage() + Constants.LINE_SEPARATOR + "Method: sanityChecks"); |
| 164 | } |
| 165 | |
| 166 | pcToBeRead.setDirty(false); |
| 167 | } else |
| 168 | { |
| 169 | errors.add("Cannot open PCG file"); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | private boolean isPCGCersion2(List<String> lines) |
| 174 | { |