@Test public void languageAndReaderWithNoData() throws IOException { StringReader emptyReader = new StringReader(""); Pair<Optional<String>, Reader> data = classUnderTest.languageAndReaderFrom(emptyReader); assertTrue(data.getFirst().isEmpty()); }
Pair<Optional<String>, Reader> languageAndReaderFrom(Reader reader) throws IOException { final char [] prefix = new char[5]; final int read = reader.read(prefix); if (read < prefix.length) { return new Pair<>(Optional.empty(), isValidLocaleMarker(prefix) ? new CharArrayReader(EMPTY_CHARSTREAM) : new CharArrayReader(prefix, 0, Math.max(read, 0))); } else { if (isValidLocaleMarker(prefix)) { if (isTwoCharsLanguageCode(prefix)) { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix, prefix.length - 1, 1); return new Pair<>( of(new String(prefix, 1, 2).toLowerCase()), new CompositeReader(alreadyConsumedCharsReader, reader)); } else { return new Pair<>( of(new String(prefix, 1, 3).toLowerCase()), reader); } } else { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix); return new Pair<>(Optional.empty(), new CompositeReader(alreadyConsumedCharsReader, reader)); } } }
LanguagePrefixedTokenStream extends Tokenizer { Pair<Optional<String>, Reader> languageAndReaderFrom(Reader reader) throws IOException { final char [] prefix = new char[5]; final int read = reader.read(prefix); if (read < prefix.length) { return new Pair<>(Optional.empty(), isValidLocaleMarker(prefix) ? new CharArrayReader(EMPTY_CHARSTREAM) : new CharArrayReader(prefix, 0, Math.max(read, 0))); } else { if (isValidLocaleMarker(prefix)) { if (isTwoCharsLanguageCode(prefix)) { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix, prefix.length - 1, 1); return new Pair<>( of(new String(prefix, 1, 2).toLowerCase()), new CompositeReader(alreadyConsumedCharsReader, reader)); } else { return new Pair<>( of(new String(prefix, 1, 3).toLowerCase()), reader); } } else { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix); return new Pair<>(Optional.empty(), new CompositeReader(alreadyConsumedCharsReader, reader)); } } } }
LanguagePrefixedTokenStream extends Tokenizer { Pair<Optional<String>, Reader> languageAndReaderFrom(Reader reader) throws IOException { final char [] prefix = new char[5]; final int read = reader.read(prefix); if (read < prefix.length) { return new Pair<>(Optional.empty(), isValidLocaleMarker(prefix) ? new CharArrayReader(EMPTY_CHARSTREAM) : new CharArrayReader(prefix, 0, Math.max(read, 0))); } else { if (isValidLocaleMarker(prefix)) { if (isTwoCharsLanguageCode(prefix)) { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix, prefix.length - 1, 1); return new Pair<>( of(new String(prefix, 1, 2).toLowerCase()), new CompositeReader(alreadyConsumedCharsReader, reader)); } else { return new Pair<>( of(new String(prefix, 1, 3).toLowerCase()), reader); } } else { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix); return new Pair<>(Optional.empty(), new CompositeReader(alreadyConsumedCharsReader, reader)); } } } LanguagePrefixedTokenStream(IndexSchema indexSchema, String fieldName, AlfrescoAnalyzerWrapper.Mode mode); }
LanguagePrefixedTokenStream extends Tokenizer { Pair<Optional<String>, Reader> languageAndReaderFrom(Reader reader) throws IOException { final char [] prefix = new char[5]; final int read = reader.read(prefix); if (read < prefix.length) { return new Pair<>(Optional.empty(), isValidLocaleMarker(prefix) ? new CharArrayReader(EMPTY_CHARSTREAM) : new CharArrayReader(prefix, 0, Math.max(read, 0))); } else { if (isValidLocaleMarker(prefix)) { if (isTwoCharsLanguageCode(prefix)) { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix, prefix.length - 1, 1); return new Pair<>( of(new String(prefix, 1, 2).toLowerCase()), new CompositeReader(alreadyConsumedCharsReader, reader)); } else { return new Pair<>( of(new String(prefix, 1, 3).toLowerCase()), reader); } } else { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix); return new Pair<>(Optional.empty(), new CompositeReader(alreadyConsumedCharsReader, reader)); } } } LanguagePrefixedTokenStream(IndexSchema indexSchema, String fieldName, AlfrescoAnalyzerWrapper.Mode mode); @Override void reset(); @Override boolean incrementToken(); @Override void end(); @Override void close(); }
LanguagePrefixedTokenStream extends Tokenizer { Pair<Optional<String>, Reader> languageAndReaderFrom(Reader reader) throws IOException { final char [] prefix = new char[5]; final int read = reader.read(prefix); if (read < prefix.length) { return new Pair<>(Optional.empty(), isValidLocaleMarker(prefix) ? new CharArrayReader(EMPTY_CHARSTREAM) : new CharArrayReader(prefix, 0, Math.max(read, 0))); } else { if (isValidLocaleMarker(prefix)) { if (isTwoCharsLanguageCode(prefix)) { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix, prefix.length - 1, 1); return new Pair<>( of(new String(prefix, 1, 2).toLowerCase()), new CompositeReader(alreadyConsumedCharsReader, reader)); } else { return new Pair<>( of(new String(prefix, 1, 3).toLowerCase()), reader); } } else { Reader alreadyConsumedCharsReader = new CharArrayReader(prefix); return new Pair<>(Optional.empty(), new CompositeReader(alreadyConsumedCharsReader, reader)); } } } LanguagePrefixedTokenStream(IndexSchema indexSchema, String fieldName, AlfrescoAnalyzerWrapper.Mode mode); @Override void reset(); @Override boolean incrementToken(); @Override void end(); @Override void close();  }