CarGuo/GSYVideoPlayer · error · ProxyCacheException
Error reading length of file ${file}
Error message
Error reading length of file ${file} What it means
FileCache.read does dataFile.seek(offset) then read(buffer, 0, length); any IOException (seek past EOF on a truncated temp file, closed RandomAccessFile, deleted file) is formatted into a message showing requested length, offset, available bytes, and buffer size - deliberately diagnostic for the classic 'cache file shorter than expected' bug.
Source
Thrown at gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/FileCache.java:48
throw new NullPointerException();
}
this.diskUsage = diskUsage;
File directory = file.getParentFile();
Files.makeDir(directory);
boolean completed = file.exists();
this.file = completed ? file : new File(file.getParentFile(), file.getName() + TEMP_POSTFIX);
this.dataFile = new RandomAccessFile(this.file, completed ? "r" : "rw");
} catch (IOException e) {
throw new ProxyCacheException("Error using file " + file + " as disc cache", e);
}
}
@Override
public synchronized long available() throws ProxyCacheException {
try {
return (int) dataFile.length();
} catch (IOException e) {
throw new ProxyCacheException("Error reading length of file " + file, e);
}
}
@Override
public synchronized int read(byte[] buffer, long offset, int length) throws ProxyCacheException {
try {
dataFile.seek(offset);
return dataFile.read(buffer, 0, length);
} catch (IOException e) {
String format = "Error reading %d bytes with offset %d from file[%d bytes] to buffer[%d bytes]";
throw new ProxyCacheException(String.format(format, length, offset, available(), buffer.length), e);
}
}
@Override
public synchronized void append(byte[] data, int length) throws ProxyCacheException {
try {
if (isCompleted()) {View on GitHub (pinned to e5d74d3aa9)
Solutions
- Ensure the origin sends correct Content-Length for range requests (no gzip on media, Accept-Encoding identity)
- On this error, delete the broken cache entry and restart playback so SourceInfo/FileCache are rebuilt
- Do not run a parallel downloader on the same cache files the proxy owns
- Verify the offset the player seeks to is within cached bounds before reading (validation wrapper)
Example fix
// before - read blindly at requested offset
int read = cache.read(buffer, offset, length);
// after - validate against available bytes
long avail = cache.available();
if (offset >= avail) {
throw new ProxyCacheException("Offset " + offset + " beyond cached " + avail + " - wait or re-open source");
}
int read = cache.read(buffer, offset, (int) Math.min(length, avail - offset)); Defensive patterns
Strategy: validation
Validate before calling
long avail = cache.available();
if (offset < 0 || offset >= avail) {
throw new IllegalArgumentException("read offset " + offset + " outside cached range [0," + avail + ")");
}
int len = (int) Math.min(length, avail - offset); Try / catch
catch (ProxyCacheException e) {
if (String.valueOf(e.getMessage()).contains("Error reading") && e.getMessage().contains("bytes with offset")) {
purgeEntryAndRestartPlayback(url); // truncated/mismatched cache file
} else throw e;
} Prevention
- Ensure the origin sends correct Content-Length (no gzip on media)
- Validate offsets against available() before reading
- Delete mismatched .download files rather than reusing them
When it happens
Trigger: Player requests bytes at an offset beyond what the .download temp file holds because SourceInfo advertised a length larger than actually cached (server lied about Content-Length, or a partial download was recorded as longer); or the fd was closed/deleted concurrently.
Common situations: Servers reporting gzip-encoded Content-Length while the proxy stores decoded bytes (length mismatch); seek into a region never downloaded after a network gap; multi-threaded download interleaving with the proxy's single-writer assumption.
Related errors
- Reading source ${sourceInfo.url} is interrupted
- Error reading source ${errorsCount} times
- Error using file ${file} as disc cache
- Error reading %d bytes with offset %d from file[%d bytes] to
- Error append cache: cache file %s is completed!
AI-assisted analysis of CarGuo/GSYVideoPlayer@e5d74d3aa9 (2026-08-14).
Data as JSON: /api/errors/c49fc8557b9baf4b.
Report an issue: GitHub.