in src/main/java/aws/cfn/codegen/SpecificationLoader.java [43:71]
public CfnSpecification loadSpecification(URL location) throws IOException {
try (PushbackInputStream stream = new PushbackInputStream(location.openStream(), 8)) {
byte[] magic = new byte[4];
int nread = stream.read(magic);
if (nread < 4) {
throw new IOException("Can not read stream");
}
int magicNum = ((int)magic[0] & 0xFF) | ((int)magic[1] & 0xFF) << 8;
Reader reader;
if (GZIPInputStream.GZIP_MAGIC == magicNum) {
stream.unread(magic);
reader = new InputStreamReader(new GZIPInputStream(stream), StandardCharsets.UTF_8);
}
else {
magicNum |= ((int)magic[2] & 0xFF) << 16 | ((int)magic[3] & 0xFF) << 24;
if (magicNum == 0x04034b50) {
stream.unread(magic);
reader = new InputStreamReader(new ZipInputStream(stream), StandardCharsets.UTF_8);
}
else {
stream.unread(magic);
reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
}
}
return mapperForJSON.readValue(reader, CfnSpecification.class);
}
}