0

サーバーから受信した ZipFile を抽出して保存したいと考えています。

このコードは半分しか機能しません。

InputStream is = socket.getInputStream();
zipStream = new ZipInputStream(new BufferedInputStream(is);

ZipEntry entry;
while ((entry = zipStream.getNextEntry()) != null) {
        String mapPaths = MAPFOLDER + entry.getName();
        Path path = Paths.get(mapPaths);
        if (Files.notExists(path)) {
            fileCreated = (new File(mapPaths)).mkdirs();
        }

        String outpath = mapPaths + "/" + entry.getName();
        FileOutputStream output = null;
        try {
            output = new FileOutputStream(outpath);
            int len = 0;
            while ((len = zipStream.read(buffer)) > 0) {
                output.write(buffer, 0, len);
            }
        } finally {
            if (output != null)
                output.close();
        }
    }

問題は、データが受信される前にメソッド zipStream.getNextEntry() が呼び出されることだと思います。受信データが読み取られるのをどのように待つことができますか?

4

0 に答える 0