diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/ShowPickled.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ShowPickled.scala | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/util/ShowPickled.scala b/src/compiler/scala/tools/nsc/util/ShowPickled.scala index f99f63dcda..20ae9c7eeb 100644 --- a/src/compiler/scala/tools/nsc/util/ShowPickled.scala +++ b/src/compiler/scala/tools/nsc/util/ShowPickled.scala @@ -14,6 +14,7 @@ import java.lang.Double.longBitsToDouble import symtab.{Flags, Names} import symtab.classfile.{PickleBuffer, PickleFormat} +import interpreter.ByteCode.scalaSigBytesForPath object ShowPickled extends Names { @@ -193,17 +194,26 @@ object ShowPickled extends Names { for (i <- 0 until index.length) printEntry(i) } - def main(args: Array[String]) { - val file = new File(args(0)) + def fromBytes(what: String, data: => Array[Byte]): Boolean = { try { - val stream = new FileInputStream(file) - val data = new Array[Byte](stream.available()) - stream.read(data) val pickle = new PickleBuffer(data, 0, data.length) + Console.println(what + ": ") printFile(pickle, Console.out) - } catch { - case ex: IOException => - Console.println("cannot read " + file + ": " + ex.getMessage()) + true + } + catch { + case _: Exception => false + } + } + + def fromFile(path: String) = fromBytes(path, io.File(path).toByteArray) + def fromName(name: String) = fromBytes(name, scalaSigBytesForPath(name) getOrElse Array()) + + def main(args: Array[String]) { + args foreach { arg => + val res = fromFile(arg) || fromName(arg) + if (!res) + Console.println("Cannot read " + arg) } } } |