(I working on download gz file -> read it -> write / save in Filebot's cache, I believe the cache will only work if string)
- Must be able to work on Linux and Windows
- I prefer to use function build into Filebot
Code: Select all
byte[] content = 'text'.getBytes()
Code: Select all
def data = args[0] as File
Cache.getCache('Manami', CacheType.Persistent).put('anime-offline-database.json', data.resolve('anime-offline-database.json.gz').bytes)
Code: Select all
Cache.getCache('Manami', CacheType.Persistent).put('anime-offline-database.json', data.resolve('anime-offline-database.json.gz').bytes)
Code: Select all
Cache.getCache('Manami', CacheType.Persistent).computeIfAbsent('anime-offline-database.json') {
data.resolve('anime-offline-database.json.gz').bytes
}
Yep, the code does exactly that and nothing else. Everything else is internal Java code.
Sorry, I don't have a copy & paste Groovy solution for that at hand. The internal FileBot code doesn't lend itself well to external Groovy scripts, so I don't have any example code for that either. I'd use standard Groovy / Java code to fetch and gunzip the file contents if you must do things from within your Groovy script.
Code: Select all
def url = 'https://files.tmdb.org/p/exports/tv_series_ids_11_01_2021.json.gz'
def bytes = Cache.getCache('exports', CacheType.Persistent).bytes(url, URL.&new, java.util.zip.GZIPInputStream.&new).get()
def text = new String(bytes, 'UTF-8')
println text
Code: Select all
bytes(url, URL.&new, GZIPInputStream.&new)
Code: Select all
bytes(url, { new URL(it) }, { new GZIPInputStream(it) } )
Code: Select all
{
import net.filebot.Cache
import net.filebot.CacheType
import java.util.zip.GZIPInputStream
def url = 'https://files.tmdb.org/p/exports/tv_series_ids_11_01_2021.json.gz'
def bytes = Cache.getCache('exports', CacheType.Persistent).bytes(url, { new URL(it) }, { new GZIPInputStream(it) } ).get()
def text = new String(bytes, 'UTF-8')
println text
}
Code: Select all
Cache.getCache('exports', CacheType.Persistent).bytes(url, { new URL(it) }, { new GZIPInputStream(it) } ).get()
Code: Select all
Cache.getCache('Manami', CacheType.Persistent).computeIfAbsent('anime-offline-database.json') {
data.resolve('anime-offline-database.json.gz').bytes
}
Don't worry. Its undocumented internal API / internal plumbing that constantly changes. I didn't even know that Groovy can automatically cast method handles to interfaces.
Code: Select all
public <T> CachedResource<T, byte[]> bytes(T key, Transform<T, URL> resource, Transform<InputStream, InputStream> decompressor)
Code: Select all
def value = Cache.getCache('string', CacheType.Persistent).computeIfAbsent(url) {
def bytes = Cache.getCache('raw', CacheType.Persistent).bytes(url, { new URL(it) }, { new GZIPInputStream(it) } ).get()
return new String(bytes, 'UTF-8')
}
Code: Select all
{
import net.filebot.Cache
import net.filebot.CacheType
import java.util.zip.GZIPInputStream
def url = 'https://files.tmdb.org/p/exports/tv_series_ids_11_01_2021.json.gz'
def value = Cache.getCache('string', CacheType.Persistent).computeIfAbsent(url) {
def bytes = Cache.getCache('raw', CacheType.Persistent).bytes(url, { new URL(it) }, { new GZIPInputStream(it) } ).get()
return new String(bytes, 'UTF-8')
}
}
Code: Select all
{
import net.filebot.Cache
import net.filebot.CacheType
import java.util.zip.GZIPInputStream
def url = 'https://files.tmdb.org/p/exports/tv_series_ids_11_01_2021.json.gz'
def bytes = Cache.getCache('exports', CacheType.Persistent).bytes(url, { new URL(it) }, { new GZIPInputStream(it) } ).get()
def text = new String(bytes, 'UTF-8')
println text
}
Code: Select all
def f = '/path/to/tv_series_ids_11_01_2021.json.gz' as File
def stream = new java.util.zip.GZIPInputStream(f.newInputStream())
def lines = stream.readLines('UTF-8')
println lines.size()