michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: michael@0: const nsIDocumentEncoder = Components.interfaces.nsIDocumentEncoder; michael@0: const replacementChar = Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER; michael@0: michael@0: function loadContentFile(aFile, aCharset) { michael@0: //if(aAsIso == undefined) aAsIso = false; michael@0: if(aCharset == undefined) michael@0: aCharset = 'UTF-8'; michael@0: michael@0: var file = do_get_file(aFile); michael@0: var ios = Components.classes['@mozilla.org/network/io-service;1'] michael@0: .getService(Components.interfaces.nsIIOService); michael@0: var chann = ios.newChannelFromURI ( ios.newFileURI (file) ); michael@0: chann.contentCharset = aCharset; michael@0: michael@0: /*var inputStream = Components.classes["@mozilla.org/scriptableinputstream;1"] michael@0: .createInstance(Components.interfaces.nsIScriptableInputStream); michael@0: inputStream.init(chann.open()); michael@0: return inputStream.read(file.fileSize); michael@0: */ michael@0: michael@0: var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"] michael@0: .createInstance(Components.interfaces.nsIConverterInputStream); michael@0: inputStream.init(chann.open(), aCharset, 1024, replacementChar); michael@0: var str = {}, content = ''; michael@0: while (inputStream.readString(4096, str) != 0) { michael@0: content += str.value; michael@0: } michael@0: return content; michael@0: }