Last active
October 18, 2016 17:20
-
-
Save krohne/a734aefccb49944e3cb3cfa0af658efa to your computer and use it in GitHub Desktop.
Nashorn Javascript CLI that will report the download size of a given URL as a command line parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!env jjs | |
// jjs filesize.js -- config.txt | |
// Sample config.txt: | |
// http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf | |
var Files = Java.type('java.nio.file.Files'); | |
var Paths = Java.type('java.nio.file.Paths'); | |
var URL = Java.type('java.net.URL'); | |
function getSize(url) { | |
var connection = new java.net.URL(url).openConnection(); | |
var len = connection.getHeaderField('Content-Length'); // Just the header, please | |
connection.disconnect(); | |
return len; | |
} | |
var configFile = arguments[0]; | |
var path = Paths.get(configFile); | |
var lines = Files.readAllLines(path); | |
var url = lines[0]; | |
print(getSize(url), '-', url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment