#TUNING by cg
class: AbstractFileBrowser class
avoid filling the virtualArray, when showing
a big file's hexdump.
comment/format in:
#contentsOfBytesAsHexDump:numberOfAddressDigits:addressStart:
#contentsOfBytesAsHexDump:numberOfAddressDigits:addressStart:characterEncoding:
changed:
#contentsOfBytesAsDump:base:numberOfAddressDigits:addressStart:characterEncoding:
#contentsOfFileAsDump:base:withLimit:lastPart:characterEncoding:
--- a/AbstractFileBrowser.st Tue Mar 12 16:43:55 2019 +0100
+++ b/AbstractFileBrowser.st Tue Mar 12 16:45:04 2019 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 2002 by eXept Software AG
All Rights Reserved
@@ -2950,13 +2952,13 @@
!AbstractFileBrowser class methodsFor:'utilities - dump'!
-contentsOfBytesAsDump:data base:numberBase numberOfAddressDigits:addrDigits addressStart:virtualStart characterEncoding:characterEncodingSymbol
+contentsOfBytesAsDump:dataOrFileStream base:numberBase numberOfAddressDigits:addrDigits addressStart:virtualStart characterEncoding:characterEncodingSymbol
"utility helper: generate a hexDump with addresses;
characterEncodingSymbol determines how characters are to be shown in the right (character) columns.
By default, this is iso8859-1, but supported are also ebcdic and ascii7,
to support display of alien encoded binary data."
- |lines nHexLines replacementForUnprintable colsPerByte characterDecoder|
+ |dataSize lines nHexLines replacementForUnprintable colsPerByte characterDecoder|
(characterEncodingSymbol isNil or:[characterEncodingSymbol == #'iso8859-1']) ifFalse:[
characterDecoder := CharacterEncoder encoderToEncodeFrom:characterEncodingSymbol into:#unicode.
@@ -2970,8 +2972,10 @@
colsPerByte := ((255 printStringRadix:numberBase) size).
"generate a virtual collection which evaluates and returns lines on-demand"
-
- nHexLines := (data size + 15) // 16.
+ dataSize := dataOrFileStream isStream
+ ifTrue:[ dataOrFileStream fileSize ]
+ ifFalse:[ dataOrFileStream size ].
+ nHexLines := (dataSize + 15) // 16.
lines := VirtualArray new.
lines setSize:nHexLines + (nHexLines // 16).
@@ -2997,12 +3001,16 @@
1 to:16 do:[:i |
i ~~ 1 ifTrue:[ lineStream space ].
- (startOffset + i) > data size ifTrue:[
+ (startOffset + i) > dataSize ifTrue:[
asciiLineStream nextPut:(Character space).
lineStream spaces:colsPerByte.
] ifFalse:[
- byte := data at:startOffset + i.
-
+ dataOrFileStream isStream ifTrue:[
+ dataOrFileStream position:(startOffset + i - 1).
+ byte := dataOrFileStream nextByte.
+ ] ifFalse:[
+ byte := dataOrFileStream at:startOffset + i.
+ ].
lineStream nextPutAll:(byte printStringRadix:numberBase size:colsPerByte fill:$0).
@@ -3021,7 +3029,7 @@
"/ are perfect here, but usually not available in the font
"/ and we have currently no way of knowing if they are...
"/ (could let the font draw into a bitmap and check if there is something...)
- "/ For now, write a dot.·
+ "/ For now, write a dot.·
"/ charPrinted := (Character value:(byte + 16r2400))
].
].
@@ -3038,14 +3046,15 @@
"Created: / 12-11-2017 / 11:24:29 / cg"
"Modified: / 12-11-2017 / 14:17:59 / cg"
-!
-
-contentsOfBytesAsHexDump:data numberOfAddressDigits:addrDigits addressStart:virtualStart
+ "Modified: / 12-03-2019 / 16:16:53 / Claus Gittinger"
+!
+
+contentsOfBytesAsHexDump:dataOrFileStream numberOfAddressDigits:addrDigits addressStart:virtualStart
"utility helper: generate a hexDump with addresses; the character columns at the right show
the iso8859-1 characters"
^ self
- contentsOfBytesAsDump:data base:16
+ contentsOfBytesAsDump:dataOrFileStream base:16
numberOfAddressDigits:addrDigits
addressStart:virtualStart
characterEncoding:#'iso8859-1'
@@ -3053,21 +3062,23 @@
"Created: / 13-02-2012 / 15:01:46 / cg"
"Modified: / 12-11-2017 / 12:07:12 / cg"
"Modified: / 14-11-2017 / 17:48:19 / mawalch"
-!
-
-contentsOfBytesAsHexDump:data numberOfAddressDigits:addrDigits addressStart:virtualStart characterEncoding:characterEncodingSymbol
+ "Modified (format): / 12-03-2019 / 16:38:26 / Claus Gittinger"
+!
+
+contentsOfBytesAsHexDump:dataOrFileStream numberOfAddressDigits:addrDigits addressStart:virtualStart characterEncoding:characterEncodingSymbol
"utility helper: generate a hexDump with addresses;
characterEncodingSymbol determines how characters are to be shown in the right (character) columns.
By default, this is iso8859-1, but supported are also ebcdic and ascii7,
to support display of alien encoded binary data."
^ self
- contentsOfBytesAsDump:data base:16
+ contentsOfBytesAsDump:dataOrFileStream base:16
numberOfAddressDigits:addrDigits
addressStart:virtualStart
characterEncoding:characterEncodingSymbol
"Created: / 12-11-2017 / 11:21:44 / cg"
+ "Modified (format): / 12-03-2019 / 16:38:31 / Claus Gittinger"
!
contentsOfFileAsDump:f base:numberBase withLimit:limitOrNil lastPart:showLastPartOrNil characterEncoding:characterEncoding
@@ -3121,17 +3132,26 @@
].
].
- stream := f readStream binary.
- sizeLimit notNil ifTrue:[
- showLastPart == true ifTrue:[
- stream position:(f fileSize - sizeLimit).
- ].
- data := stream nextBytes:sizeLimit.
- ] ifFalse:[
- data := stream contents.
- ].
- stream close.
-
+ [
+ stream := f readStream binary.
+ sizeLimit notNil ifTrue:[
+ showLastPart == true ifTrue:[
+ stream position:(f fileSize - sizeLimit).
+ ].
+ data := stream nextBytes:sizeLimit.
+ ] ifFalse:[
+ f fileSize > (1024*1024) ifTrue:[
+ data := stream
+ ] ifFalse:[
+ data := stream contents.
+ ].
+ ].
+ ] ensure:[
+ (stream notNil and:[stream ~~ data]) ifTrue:[
+ stream close.
+ ].
+ ].
+
offs := 0.
lines := StringCollection new.
@@ -3145,7 +3165,7 @@
"Created: / 12-11-2017 / 12:08:10 / cg"
"Modified: / 19-11-2017 / 15:01:34 / cg"
- "Modified: / 21-02-2019 / 17:48:48 / Claus Gittinger"
+ "Modified: / 12-03-2019 / 16:18:46 / Claus Gittinger"
!
contentsOfFileAsHexDump:f
@@ -8832,7 +8852,7 @@
] ifFalse:[sig == HaltInterrupt ifTrue:[ |sender|
label := msg := 'Breakpoint/Halt in fileIn'.
sender := ex suspendedContext.
- msg := msg , ('\\in %1 » %2' bindWith:(sender receiver class name) with:(sender sender selector))
+ msg := msg , ('\\in %1 » %2' bindWith:(sender receiver class name) with:(sender sender selector))
] ifFalse:[
label := 'Error in fileIn'.
msg := 'error in fileIn: %1'