MCPcopy Create free account
hub / github.com/SquirrelJME/SquirrelJME / __getBytes

Method __getBytes

runt/apis/cldc-compact/java/lang/String.java:1186–1225  ·  view source on GitHub ↗

Returns the encoded byte sequence. @param __e The encoder to use when writing bytes. @return The bytes from this string. @throws NullPointerException On null arguments. @since 2018/12/08

(Encoder __e)

Source from the content-addressed store, hash-verified

1184 * @since 2018/12/08
1185 */
1186 private final byte[] __getBytes(Encoder __e)
1187 throws NullPointerException
1188 {
1189 if (__e == null)
1190 throw new NullPointerException("NARG");
1191
1192 // Maximum size of sequences that can be encoded
1193 int msl;
1194 byte[] seq = new byte[(msl = __e.maximumSequenceLength())];
1195
1196 // We operate directly on the sequence
1197 BasicSequence sequence = this._sequence;
1198 int n = sequence.length();
1199
1200 // Write here
1201 try (ByteArrayOutputStream baos = new ByteArrayOutputStream(
1202 (int)(n * __e.averageSequenceLength())))
1203 {
1204 // Encode every character!
1205 for (int i = 0; i < n; i++)
1206 {
1207 int sz = __e.encode(sequence.charAt(i), seq, 0, msl);
1208
1209 // Should not occur
1210 if (sz < 0)
1211 throw new todo.OOPS();
1212
1213 baos.write(seq, 0, sz);
1214 }
1215
1216 // Use this byte array
1217 return baos.toByteArray();
1218 }
1219
1220 // Should not occur
1221 catch (IOException e)
1222 {
1223 throw new todo.OOPS();
1224 }
1225 }
1226
1227 /**
1228 * Invokes {@code String.valueOf(__c, __o, __l)}.

Callers 1

getBytesMethod · 0.95

Calls 7

lengthMethod · 0.95
charAtMethod · 0.95
maximumSequenceLengthMethod · 0.65
averageSequenceLengthMethod · 0.65
encodeMethod · 0.65
writeMethod · 0.65
toByteArrayMethod · 0.45

Tested by

no test coverage detected