semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void zipAndSendFiles(File[] logFiles) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        EmailSender emailSender = new EmailSender();
        try {
            File globalZipFile = new File("XeptoTileServer_Statistics_" + sdf.format(new Date()) + ".zip");
            ZipOutputStream globalZos = new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(globalZipFile), new Adler32()));
            BufferedOutputStream globalOut = new BufferedOutputStream(globalZos);
            globalZos.setComment("Statistics for all users from the XeptoTileServer.");
            File[] zipFiles = new File[usernames.length];
            ZipOutputStream[] zipOutputStreams = new ZipOutputStream[usernames.length];
            BufferedOutputStream[] bufferedZipStreams = new BufferedOutputStream[usernames.length];
            for (File logFile : logFiles) {
                int i;
                for (i = 0; i < usernames.length; i++) {
                    if (logFile.getName().substring(27, 28 + usernames[i].length()).equalsIgnoreCase(usernames[i] + "_")) break;
                }
                BufferedReader in = new BufferedReader(new FileReader(logFile.getPath()));
                ZipEntry entry = new ZipEntry(logFile.getName());
                globalZos.putNextEntry(entry);
                if (i < usernames.length && emails[i] != null) {
                    if (zipFiles[i] == null) {
                        zipFiles[i] = new File("XeptoTileServer_Statistics_" + usernames[i] + "_" + sdf.format(new Date()) + ".zip");
                        zipOutputStreams[i] = new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipFiles[i]), new Adler32()));
                        bufferedZipStreams[i] = new BufferedOutputStream(zipOutputStreams[i]);
                        zipOutputStreams[i].setComment("Statistics for username " + usernames[i] + " from the XeptoTileServer.");
                    }
                    zipOutputStreams[i].putNextEntry(entry);
                    int c;
                    while ((c = in.read()) != -1) {
                        globalOut.write(c);
                        bufferedZipStreams[i].write(c);
                    }
                } else {
                    int c;
                    while ((c = in.read()) != -1) globalOut.write(c);
                }
                in.close();
                logFile.delete();
            }
            globalOut.close();
            emailSender.send(java.util.ResourceBundle.getBundle("logsender_conf").getString("e-mail"), globalZipFile);
            globalZipFile.delete();
            for (int i = 0; i < zipFiles.length; i++) {
                if (zipFiles[i] != null) {
                    bufferedZipStreams[i].close();
                    emailSender.send(emails[i], zipFiles[i]);
                    zipFiles[i].delete();
                }
            }
        } catch (IOException ex) {
            System.out.println("Cannot create zip file.");
            ex.printStackTrace();
        }
    }
public static void find(String pckgname, Class tosubclass) {
        String name = new String(pckgname);
        if (!name.startsWith("/")) {
            name = "/" + name;
        }
        name = name.replace('.', '/');
        URL url = RTSI.class.getResource(name);
        System.out.println(name + "->" + url);
        if (url == null) return;
        File directory = new File(url.getFile());
        if (directory.exists()) {
            String[] files = directory.list();
            for (int i = 0; i < files.length; i++) {
                if (files[i].endsWith(".class")) {
                    String classname = files[i].substring(0, files[i].length() - 6);
                    try {
                        Object o = Class.forName(pckgname + "." + classname).newInstance();
                        if (tosubclass.isInstance(o)) {
                            System.out.println(classname);
                        }
                    } catch (ClassNotFoundException cnfex) {
                        System.err.println(cnfex);
                    } catch (InstantiationException iex) {
                    } catch (IllegalAccessException iaex) {
                    }
                }
            }
        } else {
            try {
                JarURLConnection conn = (JarURLConnection) url.openConnection();
                String starts = conn.getEntryName();
                JarFile jfile = conn.getJarFile();
                Enumeration e = jfile.entries();
                while (e.hasMoreElements()) {
                    ZipEntry entry = (ZipEntry) e.nextElement();
                    String entryname = entry.getName();
                    if (entryname.startsWith(starts) && (entryname.lastIndexOf('/') <= starts.length()) && entryname.endsWith(".class")) {
                        String classname = entryname.substring(0, entryname.length() - 6);
                        if (classname.startsWith("/")) classname = classname.substring(1);
                        classname = classname.replace('/', '.');
                        try {
                            Object o = Class.forName(classname).newInstance();
                            if (tosubclass.isInstance(o)) {
                                System.out.println(classname.substring(classname.lastIndexOf('.') + 1));
                            }
                        } catch (ClassNotFoundException cnfex) {
                            System.err.println(cnfex);
                        } catch (InstantiationException iex) {
                        } catch (IllegalAccessException iaex) {
                        }
                    }
                }
            } catch (IOException ioex) {
                System.err.println(ioex);
            }
        }
    }
public void doGet(OutputStream os) throws IOException {
        try {
            uc = (HttpURLConnection) url.openConnection();
            uc.setRequestProperty("User-Agent", USER_AGENT);
            uc.setReadTimeout(READ_TIMEOUT);
            logger.debug("Connect timeout=" + uc.getConnectTimeout() + " read timeout=" + uc.getReadTimeout() + " u=" + url);
            InputStream buffer = new BufferedInputStream(uc.getInputStream());
            int c;
            while ((c = buffer.read()) != -1) {
                os.write(c);
            }
            headers = uc.getHeaderFields();
            status = uc.getResponseCode();
            responseMessage = uc.getResponseMessage();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        } finally {
            if (status != 200) logger.error("Download failed status: " + status + " " + responseMessage + " for " + url); else logger.debug("HTTP status=" + status + " " + uc.getResponseMessage());
            os.close();
            uc.disconnect();
        }
    }
public String doGet() throws MalformedURLException, IOException {
        uc = (HttpURLConnection) url.openConnection();
        BufferedInputStream buffer = new BufferedInputStream(uc.getInputStream());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        int c;
        while ((c = buffer.read()) != -1) {
            bos.write(c);
        }
        bos.close();
        headers = uc.getHeaderFields();
        status = uc.getResponseCode();
        return bos.toString();
    }
public List<String> extractUrlList(String url) throws IOException, XPathExpressionException {
        LinkedList<String> list = new LinkedList<String>();
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        Tidy tidy = new Tidy();
        tidy.setErrout(new NullPrintWriter());
        Document doc = tidy.parseDOM(conn.getInputStream(), null);
        int len = conn.getContentLength();
        if (len <= 0) len = 32000;
        ByteArrayOutputStream bout = new ByteArrayOutputStream(len);
        PrintStream ps = new PrintStream(bout);
        tidy.pprint(doc, ps);
        ps.flush();
        String content = bout.toString();
        Pattern p = Pattern.compile("(http://[\\w\\\\\\./=&?;-]+)");
        Matcher m = p.matcher(content);
        while (m.find()) {
            list.add(m.group());
        }
        return list;
    }
private Image retrievePdsImage(double lat, double lon) {
        imageDone = false;
        try {
            StringBuffer urlBuff = new StringBuffer(psdUrl + psdCgi + "?");
            urlBuff.append("DATA_SET_NAME=" + dataSet);
            urlBuff.append("&VERSION=" + version);
            urlBuff.append("&PIXEL_TYPE=" + pixelType);
            urlBuff.append("&PROJECTION=" + projection);
            urlBuff.append("&STRETCH=" + stretch);
            urlBuff.append("&GRIDLINE_FREQUENCY=" + gridlineFrequency);
            urlBuff.append("&SCALE=" + URLEncoder.encode(scale));
            urlBuff.append("&RESOLUTION=" + resolution);
            urlBuff.append("&LATBOX=" + latbox);
            urlBuff.append("&LONBOX=" + lonbox);
            urlBuff.append("&BANDS_SELECTED=" + bandsSelected);
            urlBuff.append("&LAT=" + lat);
            urlBuff.append("&LON=" + lon);
            URL url = new URL(urlBuff.toString());
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String result = null;
            String line;
            String imageSrc;
            int count = 0;
            while ((line = in.readLine()) != null) {
                if (count == 6) result = line;
                count++;
            }
            int startIndex = result.indexOf("<TH COLSPAN=2 ROWSPAN=2><IMG SRC = \"") + 36;
            int endIndex = result.indexOf("\"", startIndex);
            imageSrc = result.substring(startIndex, endIndex);
            URL imageUrl = new URL(imageSrc);
            return (Toolkit.getDefaultToolkit().getImage(imageUrl));
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return null;
    }
public static String readUrl(String urlString) {
        try {
            java.net.URL url = new java.net.URL(urlString);
            BufferedReader br = null;
            if (url != null) {
                br = new BufferedReader(new InputStreamReader(url.openStream()));
            }
            StringBuffer fileString = new StringBuffer();
            while (true) {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                fileString.append(line + "\n");
            }
            return fileString.toString();
        } catch (Exception e) {
            return null;
        }
    }
@Override
    public String getMD5(String host) {
        String res = "";
        Double randNumber = Math.random() + System.currentTimeMillis();
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(randNumber.toString().getBytes());
            byte[] md5 = algorithm.digest();
            String tmp = "";
            for (int i = 0; i < md5.length; i++) {
                tmp = (Integer.toHexString(0xFF & md5[i]));
                if (tmp.length() == 1) {
                    res += "0" + tmp;
                } else {
                    res += tmp;
                }
            }
        } catch (Exception ex) {
        }
        return res;
    }
public static String encryptMd5(String plaintext) {
        String hashtext = "";
        try {
            MessageDigest m;
            m = MessageDigest.getInstance("MD5");
            m.reset();
            m.update(plaintext.getBytes());
            byte[] digest = m.digest();
            BigInteger bigInt = new BigInteger(1, digest);
            hashtext = bigInt.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return hashtext;
    }
public void insert() throws Exception {
        Connection con = DbUtil.connectToDb();
        PreparedStatement pStmt = null;
        try {
            pStmt = con.prepareStatement("INSERT INTO " + Constants.TABLENAME + " (name,phone,address)" + " values(?,?,?)");
            con.setAutoCommit(false);
            pStmt.setString(1, name);
            pStmt.setString(2, phone);
            pStmt.setString(3, address);
            int j = pStmt.executeUpdate();
            con.commit();
        } catch (Exception ex) {
            try {
                con.rollback();
            } catch (SQLException sqlex) {
                sqlex.printStackTrace(System.out);
            }
            throw ex;
        } finally {
            try {
                pStmt.close();
                con.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
public static HttpURLConnection getHttpConn(String urlStr, String Method) throws IOException {
        URL url = null;
        HttpURLConnection connection = null;
        url = new URL(urlStr);
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod(Method);
        connection.setUseCaches(false);
        connection.connect();
        return connection;
    }
public static void doHttpPost(String urlName, byte[] data, String contentType, String cookieData) throws InteropException {
        URL url = getAccessURL(urlName);
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Cookie", cookieData);
            connection.setRequestProperty("Content-type", contentType);
            connection.setRequestProperty("Content-length", "" + data.length);
            OutputStream stream = connection.getOutputStream();
            stream.write(data);
            stream.flush();
            stream.close();
            connection.connect();
            InputStream inputStream = connection.getInputStream();
            inputStream.close();
        } catch (IOException ex) {
            throw new InteropException("Error POSTing to " + urlName, ex);
        }
    }
public void copyServer(int id) throws Exception {
        File in = new File("servers" + File.separatorChar + "server_" + id);
        File serversDir = new File("servers" + File.separatorChar);
        int newNumber = serversDir.listFiles().length + 1;
        System.out.println("New File Number: " + newNumber);
        File out = new File("servers" + File.separatorChar + "server_" + newNumber);
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
        getServer(newNumber - 1);
    }
public void run() {
        try {
            URL url = new URL(UPDATE_URL);
            URLConnection urlc = url.openConnection();
            BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            String versionString = br.readLine();
            if (versionString != null && !versionString.equals(PinEmUp.VERSION)) {
                StringBuilder changelogString = new StringBuilder();
                changelogString.append("<html>");
                changelogString.append("<p>" + I18N.getInstance().getString("info.updateavailable.part1") + "</p>");
                changelogString.append("<p>" + I18N.getInstance().getString("info.updateavailable.part2") + " " + PinEmUp.VERSION + "<br />");
                changelogString.append(I18N.getInstance().getString("info.updateavailable.part3") + " " + versionString + "</p>");
                changelogString.append("<p>" + I18N.getInstance().getString("info.updateavailable.part4") + " <a href=\"http://pinemup.sourceforge.net\">http://pinemup.sourceforge.net</a></p>");
                changelogString.append("<p>&nbsp;</p>");
                changelogString.append("<p>Changelog:<br />");
                changelogString.append("--------------------------------</p><p>");
                boolean firstList = true;
                String nextLine;
                do {
                    nextLine = br.readLine();
                    if (nextLine != null) {
                        if (nextLine.startsWith("-")) {
                            changelogString.append("<li>" + nextLine.substring(2) + "</li>");
                        } else {
                            if (!firstList) {
                                changelogString.append("</ul>");
                            } else {
                                firstList = false;
                            }
                            changelogString.append(nextLine + "<ul>");
                        }
                    }
                } while (nextLine != null);
                changelogString.append("</p></html>");
                new UpdateDialog(changelogString.toString());
            } else if (showUpToDateMessage) {
                JOptionPane.showMessageDialog(null, I18N.getInstance().getString("info.versionuptodate"), I18N.getInstance().getString("info.title"), JOptionPane.INFORMATION_MESSAGE);
            }
            br.close();
        } catch (IOException e) {
        }
    }
public int download() {
        FTPClient client = null;
        URL url = null;
        try {
            client = new FTPClient();
            url = new URL(ratingsUrl);
            if (log.isDebugEnabled()) log.debug("Downloading " + url);
            client.connect(url.getHost());
            int reply = client.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                if (log.isErrorEnabled()) log.error("Connection to " + url + " refused");
                return RESULT_CONNECTION_REFUSED;
            }
            if (log.isDebugEnabled()) log.debug("Logging in  l:" + getUserName() + " p:" + getPassword());
            client.login(getUserName(), getPassword());
            client.changeWorkingDirectory(url.getPath());
            FTPFile[] files = client.listFiles(url.getPath());
            if ((files == null) || (files.length != 1)) throw new FileNotFoundException("No remote file");
            FTPFile remote = files[0];
            if (log.isDebugEnabled()) log.debug("Remote file data: " + remote);
            File local = new File(getOutputFile());
            if (local.exists()) {
                if ((local.lastModified() == remote.getTimestamp().getTimeInMillis())) {
                    if (log.isDebugEnabled()) log.debug("File " + local.getAbsolutePath() + " is not changed on the server");
                    return RESULT_NO_NEW_FILE;
                }
            }
            if (log.isDebugEnabled()) log.debug("Setting binary transfer modes");
            client.mode(FTPClient.BINARY_FILE_TYPE);
            client.setFileType(FTPClient.BINARY_FILE_TYPE);
            OutputStream fos = new FileOutputStream(local);
            boolean result = client.retrieveFile(url.getPath(), fos);
            if (log.isDebugEnabled()) log.debug("The transfer result is :" + result);
            fos.flush();
            fos.close();
            local.setLastModified(remote.getTimestamp().getTimeInMillis());
            if (result) uncompress();
            if (result) return RESULT_OK; else return RESULT_TRANSFER_ERROR;
        } catch (MalformedURLException e) {
            return RESULT_ERROR;
        } catch (SocketException e) {
            return RESULT_ERROR;
        } catch (FileNotFoundException e) {
            return RESULT_ERROR;
        } catch (IOException e) {
            return RESULT_ERROR;
        } finally {
            if (client != null) {
                try {
                    if (log.isDebugEnabled()) log.debug("Logging out");
                    client.logout();
                } catch (Exception e) {
                }
                try {
                    if (log.isDebugEnabled()) log.debug("Disconnecting");
                    client.disconnect();
                } catch (Exception e) {
                }
            }
        }
    }
private static Pattern getBotPattern() {
        StringBuilder sb = new StringBuilder();
        try {
            Enumeration<URL> urls = AbstractPustefixRequestHandler.class.getClassLoader().getResources(CONFIG);
            while (urls.hasMoreElements()) {
                URL url = urls.nextElement();
                InputStream in = url.openStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf8"));
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (!line.startsWith("#") && !line.equals("")) {
                        if (sb.length() > 0) sb.append("|");
                        sb.append("(").append(line).append(")");
                    }
                }
                in.close();
            }
        } catch (IOException e) {
            throw new RuntimeException("Error reading bot user-agent configuration", e);
        }
        return Pattern.compile(sb.toString());
    }
public static void main(String[] args) throws IOException, DataFormatException {
        byte in_buf[] = new byte[20000];
        if (args.length < 2) {
            System.out.println("too few arguments");
            System.exit(0);
        }
        String inputName = args[0];
        InputStream in = new FileInputStream(inputName);
        int index = 0;
        for (int i = 1; i < args.length; i++) {
            int size = Integer.parseInt(args[i]);
            boolean copy = size >= 0;
            if (size < 0) {
                size = -size;
            }
            OutputStream out = null;
            if (copy) {
                index++;
                out = new FileOutputStream(inputName + "." + index + ".dat");
            }
            while (size > 0) {
                int read = in.read(in_buf, 0, Math.min(in_buf.length, size));
                if (read < 0) {
                    break;
                }
                size -= read;
                if (copy) {
                    out.write(in_buf, 0, read);
                }
            }
            if (copy) {
                out.close();
            }
        }
        index++;
        OutputStream out = new FileOutputStream(inputName + "." + index + ".dat");
        while (true) {
            int read = in.read(in_buf);
            if (read < 0) {
                break;
            }
            out.write(in_buf, 0, read);
        }
        out.close();
        in.close();
    }
public void bubblesort(String filenames[]) {
        for (int i = filenames.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                String temp;
                if (filenames[j].compareTo(filenames[j + 1]) > 0) {
                    temp = filenames[j];
                    filenames[j] = filenames[j + 1];
                    filenames[j + 1] = temp;
                }
            }
        }
    }
private byte[] cacheInputStream(URL url) throws IOException {
            InputStream ins = url.openStream();
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            byte[] buf = new byte[256];
            while (true) {
                int n = ins.read(buf);
                if (n == -1) break;
                bout.write(buf, 0, n);
            }
            return bout.toByteArray();
        }
public void scan() throws Throwable {
        client = new FTPClient();
        log.info("connecting to " + host + "...");
        client.connect(host);
        log.info(client.getReplyString());
        log.info("logging in...");
        client.login("anonymous", "");
        log.info(client.getReplyString());
        Date date = Calendar.getInstance().getTime();
        xmlDocument = new XMLDocument(host, dir, date);
        scanDirectory(dir);
    }