2929import java .nio .MappedByteBuffer ;
3030import java .nio .channels .FileChannel ;
3131import java .nio .channels .FileChannel .MapMode ;
32- import java .nio .charset .CharacterCodingException ;
33- import java .nio .charset .CharsetDecoder ;
3432import java .nio .file .Path ;
3533import java .nio .file .StandardOpenOption ;
3634import java .util .Iterator ;
@@ -111,7 +109,6 @@ static class ZipIterator implements Iterator<Entry> {
111109 private final Path path ;
112110 private int cdindex = 0 ;
113111 private final MappedByteBuffer cd ;
114- private final CharsetDecoder decoder = UTF_8 .newDecoder ();
115112
116113 ZipIterator (Path path , FileChannel chan , MappedByteBuffer cd ) {
117114 this .path = path ;
@@ -138,15 +135,15 @@ public Entry next() {
138135 }
139136
140137 public String string (ByteBuffer buf , int offset , int length ) {
138+ // TODO: cushon - switch to FFM on JDK 22+
139+ // MemorySegment.copy(MemorySegment.ofBuffer(buf), JAVA_BYTE, offset, bytes, 0, length);
140+ // TODO: cushon - switch to MemorySegment#getString on JDK 27(?)+
141+ // MemorySegment.ofBuffer(buf).getString(offset, UTF_8, length);
141142 buf = buf .duplicate ();
142143 buf .position (offset );
143- buf .limit (offset + length );
144- decoder .reset ();
145- try {
146- return decoder .decode (buf ).toString ();
147- } catch (CharacterCodingException e ) {
148- throw new IOError (e );
149- }
144+ byte [] bytes = new byte [length ];
145+ buf .get (bytes );
146+ return new String (bytes , UTF_8 );
150147 }
151148 }
152149
0 commit comments