<commit_before><commit_msg>Add snippets: download file by Java<commit_after>package net;

import java.net.URL;
import java.io.IOException;
import java.io.File;
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.ByteArrayOutputStream;

public class DownloadFile {
    public static void main(String[] args) {

        String picUrl = "https://mazhuang.org/assets/images/qrcode.jpg";

        String tempPath =System.getProperty("java.io.tmpdir");
        String fileName = String.valueOf(System.currentTimeMillis());
        int index = picUrl.lastIndexOf(".");
        String suffix = picUrl.substring(index);
        fileName += suffix;
        String filePath = tempPath + fileName;

        System.out.println("file path: " + filePath);

        boolean result = downloadPicture(picUrl, filePath);
        System.out.println("download result: " + result);
    }

    public static boolean downloadPicture(String picUrl, String filePath) {
        URL url;

        try {
            url = new URL(picUrl);
            DataInputStream dataInputStream = new DataInputStream(url.openStream());

            FileOutputStream fileOutputStream = new FileOutputStream(new File(filePath));
            ByteArrayOutputStream output = new ByteArrayOutputStream();

            byte[] buffer = new byte[1024];
            int length;

            while ((length = dataInputStream.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            }
            fileOutputStream.write(output.toByteArray());
            dataInputStream.close();
            fileOutputStream.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;
    }
}
{'fraction_non_alphanumeric': 0.10457142857142857, 'fraction_numerical': 0.0034285714285714284, 'mean_word_length': 2.5160642570281126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4612864', 'n_tokens_mistral': 453, 'n_tokens_neox': 438, 'n_words': 108}