mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 00:50:31 +00:00
Append first few characters of binary trips result (Hafas) to exception, for debug purposes.
This commit is contained in:
parent
67db7d7b2d
commit
4591eede54
2 changed files with 15 additions and 1 deletions
|
@ -1609,13 +1609,16 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
try
|
||||
{
|
||||
final CustomBufferedInputStream bis = new CustomBufferedInputStream(ParserUtils.scrapeInputStream(uri));
|
||||
final String firstChars = ParserUtils.peekFirstChars(bis);
|
||||
|
||||
// initialize input stream
|
||||
is = new LittleEndianDataInputStream(bis);
|
||||
is.mark(expectedBufferSize);
|
||||
|
||||
// quick check of status
|
||||
final int version = is.readShortReverse();
|
||||
if (version != 6 && version != 5)
|
||||
throw new IllegalStateException("unknown version: " + version);
|
||||
throw new IllegalStateException("unknown version: " + version + ", first chars: " + firstChars);
|
||||
final ResultHeader header = new ResultHeader(SERVER_PRODUCT, Integer.toString(version), 0, null);
|
||||
|
||||
// quick seek for pointers
|
||||
|
|
|
@ -362,6 +362,17 @@ public final class ParserUtils
|
|||
}
|
||||
}
|
||||
|
||||
private static final int PEEK_SIZE = 2048;
|
||||
|
||||
public static String peekFirstChars(final InputStream is) throws IOException
|
||||
{
|
||||
is.mark(PEEK_SIZE);
|
||||
final byte[] firstBytes = new byte[PEEK_SIZE];
|
||||
final int read = is.read(firstBytes);
|
||||
is.reset();
|
||||
return new String(firstBytes, 0, read).replaceAll("\\p{C}", "");
|
||||
}
|
||||
|
||||
private static final Pattern P_ENTITY = Pattern.compile("&(?:#(x[\\da-f]+|\\d+)|(amp|quot|apos|szlig|nbsp));");
|
||||
|
||||
public static String resolveEntities(final CharSequence str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue