Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | const enablePrivilege = netscape.security.PrivilegeManager.enablePrivilege; |
michael@0 | 7 | const IOSERVICE_CTRID = "@mozilla.org/network/io-service;1"; |
michael@0 | 8 | const nsIIOService = Components.interfaces.nsIIOService; |
michael@0 | 9 | const SIS_CTRID = "@mozilla.org/scriptableinputstream;1"; |
michael@0 | 10 | const nsISIS = Components.interfaces.nsIScriptableInputStream; |
michael@0 | 11 | const nsIFilePicker = Components.interfaces.nsIFilePicker; |
michael@0 | 12 | const STDURL_CTRID = "@mozilla.org/network/standard-url;1"; |
michael@0 | 13 | const nsIURI = Components.interfaces.nsIURI; |
michael@0 | 14 | |
michael@0 | 15 | var gStop = false; |
michael@0 | 16 | |
michael@0 | 17 | function loadFile(aUriSpec) |
michael@0 | 18 | { |
michael@0 | 19 | enablePrivilege('UniversalXPConnect'); |
michael@0 | 20 | var serv = Components.classes[IOSERVICE_CTRID]. |
michael@0 | 21 | getService(nsIIOService); |
michael@0 | 22 | if (!serv) { |
michael@0 | 23 | throw Components.results.ERR_FAILURE; |
michael@0 | 24 | } |
michael@0 | 25 | var chan = serv.newChannel(aUriSpec, null, null); |
michael@0 | 26 | var instream = |
michael@0 | 27 | Components.classes[SIS_CTRID].createInstance(nsISIS); |
michael@0 | 28 | instream.init(chan.open()); |
michael@0 | 29 | |
michael@0 | 30 | return instream.read(instream.available()); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function dump20(aVal) |
michael@0 | 34 | { |
michael@0 | 35 | const pads = ' '; |
michael@0 | 36 | if (typeof(aVal)=='string') |
michael@0 | 37 | out = aVal; |
michael@0 | 38 | else if (typeof(aVal)=='number') |
michael@0 | 39 | out = Number(aVal).toFixed(2); |
michael@0 | 40 | else |
michael@0 | 41 | out = new String(aVal); |
michael@0 | 42 | dump(pads.substring(0, 20 - out.length)); |
michael@0 | 43 | dump(out); |
michael@0 | 44 | } |