private static int skipSpace(InputAccessor paramInputAccessor, byte paramByte) { while (true) { int i = paramByte & 0xFF; if ((i != 32) && (i != 13) && (i != 10) && (i != 9)) return i; if (!paramInputAccessor.hasMoreBytes()) return -1; paramByte = paramInputAccessor.nextByte(); } }
private static MatchStrength tryMatch(InputAccessor paramInputAccessor, String paramString, MatchStrength paramMatchStrength) { int i = 0; int j = paramString.length(); while (i < j) { if (!paramInputAccessor.hasMoreBytes()) return MatchStrength.INCONCLUSIVE; if (paramInputAccessor.nextByte() != paramString.charAt(i)) return MatchStrength.NO_MATCH; i++; } return paramMatchStrength; }
private static MatchStrength tryMatch(InputAccessor acc, String matchStr, MatchStrength fullMatchStrength) throws IOException { for (int i = 0, len = matchStr.length(); i < len; ++i) { if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } if (acc.nextByte() != matchStr.charAt(i)) { return MatchStrength.NO_MATCH; } } return fullMatchStrength; }
private static int skipSpace(InputAccessor acc) throws IOException { if (!acc.hasMoreBytes()) { return -1; } return skipSpace(acc, acc.nextByte()); }
private static int skipSpace(InputAccessor acc, byte b) throws IOException { while (true) { int ch = (int) b & 0xFF; if (!(ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t')) { return ch; } if (!acc.hasMoreBytes()) { return -1; } b = acc.nextByte(); ch = (int) b & 0xFF; } }
public MatchStrength hasFormat(InputAccessor acc) throws IOException { // since we can't keep this abstract, only implement for "vanilla" instance if (getClass() == JsonFactory.class) { return hasJSONFormat(acc); } return null; }
/** * Sub-classes need to override this method (as of 1.8) */ @Override public MatchStrength hasFormat(InputAccessor acc) throws IOException { if (getClass() == MappingJsonFactory.class) { return hasJSONFormat(acc); } return null; }
/** * Sub-classes need to override this method (as of 1.8) */ @Override public MatchStrength hasFormat(InputAccessor acc) throws IOException { if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } byte b = acc.nextByte(); // Very first thing, a UTF-8 BOM? if (b == UTF8_BOM_1) { // yes, looks like UTF-8 BOM if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } if (acc.nextByte() != UTF8_BOM_2) { return MatchStrength.NO_MATCH; } if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } if (acc.nextByte() != UTF8_BOM_3) { return MatchStrength.NO_MATCH; } if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } b = acc.nextByte(); } if (b == '{' || Character.isLetter((char) b) || Character.isDigit((char) b)) { return MatchStrength.WEAK_MATCH; } return MatchStrength.INCONCLUSIVE; }
public MatchStrength hasFormat(InputAccessor paramInputAccessor) { if (getClass() == MappingJsonFactory.class) return hasJSONFormat(paramInputAccessor); return null; }
public static MatchStrength hasJSONFormat(InputAccessor paramInputAccessor) { if (!paramInputAccessor.hasMoreBytes()) return MatchStrength.INCONCLUSIVE; byte b1 = paramInputAccessor.nextByte(); byte b2 = b1; if (b1 == -17) { if (!paramInputAccessor.hasMoreBytes()) return MatchStrength.INCONCLUSIVE; if (paramInputAccessor.nextByte() != -69) return MatchStrength.NO_MATCH; if (!paramInputAccessor.hasMoreBytes()) return MatchStrength.INCONCLUSIVE; if (paramInputAccessor.nextByte() != -65) return MatchStrength.NO_MATCH; if (!paramInputAccessor.hasMoreBytes()) return MatchStrength.INCONCLUSIVE; b2 = paramInputAccessor.nextByte(); } int i = skipSpace(paramInputAccessor, b2); if (i < 0) return MatchStrength.INCONCLUSIVE; if (i == 123) { int m = skipSpace(paramInputAccessor); if (m < 0) return MatchStrength.INCONCLUSIVE; if ((m == 34) || (m == 125)) return MatchStrength.SOLID_MATCH; return MatchStrength.NO_MATCH; } if (i == 91) { int k = skipSpace(paramInputAccessor); if (k < 0) return MatchStrength.INCONCLUSIVE; if ((k == 93) || (k == 91)) return MatchStrength.SOLID_MATCH; return MatchStrength.SOLID_MATCH; } MatchStrength localMatchStrength = MatchStrength.WEAK_MATCH; if (i == 34) return localMatchStrength; if ((i <= 57) && (i >= 48)) return localMatchStrength; if (i == 45) { int j = skipSpace(paramInputAccessor); if (j < 0) return MatchStrength.INCONCLUSIVE; if ((j <= 57) && (j >= 48)) return localMatchStrength; return MatchStrength.NO_MATCH; } if (i == 110) return tryMatch(paramInputAccessor, "ull", localMatchStrength); if (i == 116) return tryMatch(paramInputAccessor, "rue", localMatchStrength); if (i == 102) return tryMatch(paramInputAccessor, "alse", localMatchStrength); return MatchStrength.NO_MATCH; }
private static int skipSpace(InputAccessor paramInputAccessor) { if (!paramInputAccessor.hasMoreBytes()) return -1; return skipSpace(paramInputAccessor, paramInputAccessor.nextByte()); }
public MatchStrength hasFormat(InputAccessor paramInputAccessor) { if (getClass() == JsonFactory.class) return hasJSONFormat(paramInputAccessor); return null; }
public MatchStrength hasJSONFormat(InputAccessor paramInputAccessor) { return ByteSourceJsonBootstrapper.hasJSONFormat(paramInputAccessor); }
public static MatchStrength hasSmileFormat(InputAccessor acc) throws IOException { // Ok: ideally we start with the header -- if so, we are golden if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } // We always need at least two bytes to determine, so byte b1 = acc.nextByte(); if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } byte b2 = acc.nextByte(); // First: do we see 3 "magic bytes"? If so, we are golden if (b1 == SmileConstants.HEADER_BYTE_1) { // yeah, looks like marker if (b2 != SmileConstants.HEADER_BYTE_2) { return MatchStrength.NO_MATCH; } if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } return (acc.nextByte() == SmileConstants.HEADER_BYTE_3) ? MatchStrength.FULL_MATCH : MatchStrength.NO_MATCH; } // Otherwise: ideally either Object or Array: if (b1 == SmileConstants.TOKEN_LITERAL_START_OBJECT) { /* Object is bit easier, because now we need to get new name; i.e. can * rule out name back-refs */ if (b2 == SmileConstants.TOKEN_KEY_LONG_STRING) { return MatchStrength.SOLID_MATCH; } int ch = (int) b2 & 0xFF; if (ch >= 0x80 && ch < 0xF8) { return MatchStrength.SOLID_MATCH; } return MatchStrength.NO_MATCH; } // Array bit trickier if (b1 == SmileConstants.TOKEN_LITERAL_START_ARRAY) { if (!acc.hasMoreBytes()) { return MatchStrength.INCONCLUSIVE; } /* For arrays, we will actually accept much wider range of values (including * things that could otherwise collide) */ if (likelySmileValue(b2) || possibleSmileValue(b2, true)) { return MatchStrength.SOLID_MATCH; } return MatchStrength.NO_MATCH; } // Scalar values are pretty weak, albeit possible; require more certain match, consider it weak: if (likelySmileValue(b1) || possibleSmileValue(b2, false)) { return MatchStrength.SOLID_MATCH; } return MatchStrength.NO_MATCH; }
/** * Sub-classes need to override this method (as of 1.8) */ @Override public MatchStrength hasFormat(InputAccessor acc) throws IOException { return SmileParserBootstrapper.hasSmileFormat(acc); }
/** * Helper method that can be called to determine if content accessed * using given accessor seems to be JSON content. */ protected MatchStrength hasJSONFormat(InputAccessor acc) throws IOException { return ByteSourceJsonBootstrapper.hasJSONFormat(acc); }