MCPcopy Create free account
hub / github.com/PCGen/pcgen / read

Method read

code/src/java/pcgen/io/PCGIOHandler.java:127–171  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 {

Callers 2

openPcInternalMethod · 0.95
runWriteReadMethod · 0.95

Calls 15

readPcgLinesMethod · 0.95
isPCGCersion2Method · 0.95
parsePCGMethod · 0.95
errorPrintMethod · 0.95
getFormattedStringMethod · 0.95
getWarningsMethod · 0.95
sanityChecksMethod · 0.95
setImportingMethod · 0.80
getMethodMethod · 0.80
getLineMethod · 0.80
clearMethod · 0.65
getMessageMethod · 0.65

Tested by 1

runWriteReadMethod · 0.76