equal
deleted
inserted
replaced
8 |
8 |
9 |
9 |
10 import java.io.{File => JFile, ByteArrayOutputStream, ByteArrayInputStream, |
10 import java.io.{File => JFile, ByteArrayOutputStream, ByteArrayInputStream, |
11 OutputStream, InputStream, FileInputStream, FileOutputStream} |
11 OutputStream, InputStream, FileInputStream, FileOutputStream} |
12 import java.net.URL |
12 import java.net.URL |
|
13 import java.util.Base64 |
13 |
14 |
14 import org.tukaani.xz.{XZInputStream, XZOutputStream} |
15 import org.tukaani.xz.{XZInputStream, XZOutputStream} |
15 |
16 |
16 |
17 |
17 object Bytes |
18 object Bytes |
149 lazy val sha1_digest: SHA1.Digest = SHA1.digest(bytes) |
150 lazy val sha1_digest: SHA1.Digest = SHA1.digest(bytes) |
150 |
151 |
151 def text: String = |
152 def text: String = |
152 UTF8.decode_chars(s => s, bytes, offset, offset + length).toString |
153 UTF8.decode_chars(s => s, bytes, offset, offset + length).toString |
153 |
154 |
|
155 def base64: String = |
|
156 { |
|
157 val b = |
|
158 if (offset == 0 && length == bytes.length) bytes |
|
159 else Bytes(bytes, offset, length).bytes |
|
160 Base64.getEncoder.encodeToString(b) |
|
161 } |
|
162 |
154 override def toString: String = |
163 override def toString: String = |
155 { |
164 { |
156 val str = text |
165 val str = text |
157 if (str.contains('\uFFFD')) "Bytes(" + length + ")" else str |
166 if (str.contains('\uFFFD')) "Bytes(" + length + ")" else str |
158 } |
167 } |