semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void writeStatsToDatabase(long transferJobAIPCount, long reprocessingJobAIPCount, long transferJobAIPVolume, long reprocessingJobAIPVolume, long overallBinaryAIPCount, Map<String, AIPStatistics> mimeTypeRegister) throws SQLException {
        int nextAIPStatsID;
        long nextMimetypeStatsID;
        Statement select = dbConnection.createStatement();
        String aipStatsQuery = "select max(aip_statistics_id) from aip_statistics";
        ResultSet result = select.executeQuery(aipStatsQuery);
        if (result.next()) {
            nextAIPStatsID = result.getInt(1) + 1;
        } else {
            throw new SQLException("Problem getting maximum AIP Statistics ID");
        }
        String mimetypeStatsQuery = "select max(mimetype_aip_statistics_id) from mimetype_aip_statistics";
        result = select.executeQuery(mimetypeStatsQuery);
        if (result.next()) {
            nextMimetypeStatsID = result.getLong(1) + 1;
        } else {
            throw new SQLException("Problem getting maximum MIME type AIP Statistics ID");
        }
        String insertAIPStatsEntryQuery = "insert into aip_statistics " + "(aip_statistics_id, tj_aip_count, tj_aip_volume, rj_aip_count, rj_aip_volume, " + "collation_date, binary_aip_count) " + "values (?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement insert = dbConnection.prepareStatement(insertAIPStatsEntryQuery);
        insert.setInt(1, nextAIPStatsID);
        insert.setLong(2, transferJobAIPCount);
        insert.setLong(3, transferJobAIPVolume);
        insert.setLong(4, reprocessingJobAIPCount);
        insert.setLong(5, reprocessingJobAIPVolume);
        insert.setDate(6, new java.sql.Date(System.currentTimeMillis()));
        insert.setLong(7, overallBinaryAIPCount);
        int rowsAdded = insert.executeUpdate();
        if (rowsAdded != 1) {
            dbConnection.rollback();
            throw new SQLException("Could not insert row into AIP statistics table");
        }
        String insertMimeTypeStatsQuery = "insert into mimetype_aip_statistics " + "(mimetype_aip_statistics_id, aip_statistics_id, mimetype_aip_count, mimetype_aip_volume, mimetype) " + "values (?, ?, ?, ?, ?)";
        insert = dbConnection.prepareStatement(insertMimeTypeStatsQuery);
        insert.setInt(2, nextAIPStatsID);
        for (String mimeType : mimeTypeRegister.keySet()) {
            AIPStatistics mimeTypeStats = mimeTypeRegister.get(mimeType);
            insert.setLong(1, nextMimetypeStatsID);
            insert.setLong(3, mimeTypeStats.aipCount);
            insert.setLong(4, mimeTypeStats.aipVolume);
            insert.setString(5, mimeType);
            nextMimetypeStatsID++;
            rowsAdded = insert.executeUpdate();
            if (rowsAdded != 1) {
                dbConnection.rollback();
                throw new SQLException("Could not insert row into MIME Type AIP statistics table");
            }
        }
        dbConnection.commit();
    }
public SimplePropertiesMessageRepository() {
        properties = new Properties();
        try {
            URL url = SimplePropertiesIconRepository.class.getResource(PROPERTIES_FILE_NAME);
            properties.load(url.openStream());
        } catch (Exception e) {
            throw new Error("Messages file not found: " + PROPERTIES_FILE_NAME);
        }
    }
private void readAnnotations() throws IOException {
        final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        try {
            String line = null;
            while ((line = in.readLine()) != null) {
                lineNumber++;
                if (line.startsWith("ANNOTATE")) {
                    readAnnotationBlock(in);
                }
            }
        } catch (IOException e) {
            throw e;
        } finally {
            in.close();
        }
    }
protected InputStream callApiMethod(String apiUrl, int expected) {
        try {
            URL url = new URL(apiUrl);
            HttpURLConnection request = (HttpURLConnection) url.openConnection();
            for (String headerName : requestHeaders.keySet()) {
                request.setRequestProperty(headerName, requestHeaders.get(headerName));
            }
            request.connect();
            if (request.getResponseCode() != expected) {
                Error error = readResponse(Error.class, getWrappedInputStream(request.getErrorStream(), GZIP_ENCODING.equalsIgnoreCase(request.getContentEncoding())));
                throw createBingSearchApiClientException(error);
            } else {
                return getWrappedInputStream(request.getInputStream(), GZIP_ENCODING.equalsIgnoreCase(request.getContentEncoding()));
            }
        } catch (IOException e) {
            throw new BingSearchException(e);
        }
    }
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(inputResource.getInputStream()));
        File targetDirectoryAsFile = new File(targetDirectory);
        if (!targetDirectoryAsFile.exists()) {
            FileUtils.forceMkdir(targetDirectoryAsFile);
        }
        File target = new File(targetDirectory, targetFile);
        BufferedOutputStream dest = null;
        while (zis.getNextEntry() != null) {
            if (!target.exists()) {
                target.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(target);
            dest = new BufferedOutputStream(fos);
            IOUtils.copy(zis, dest);
            dest.flush();
            dest.close();
        }
        zis.close();
        if (!target.exists()) {
            throw new IllegalStateException("Could not decompress anything from the archive!");
        }
        return RepeatStatus.FINISHED;
    }
public static void sortSeries(double[] series) {
        if (series == null) {
            throw new IllegalArgumentException("Incorrect series. It's null-pointed");
        }
        int k = 0;
        int right = series.length - 1;
        while (right > 0) {
            k = 0;
            for (int i = 0; i <= right - 1; i++) {
                if (series[i] > series[i + 1]) {
                    k = i;
                    double tmp = series[i];
                    series[i] = series[i + 1];
                    series[i + 1] = tmp;
                }
            }
            right = k;
        }
    }
public static String md5String(String str) {
        try {
            MessageDigest md;
            md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            byte[] hash = md.digest();
            final char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
            StringBuffer res = new StringBuffer();
            for (int i = 0; i < hash.length; i++) {
                res.append(hexChars[(0xF0 & hash[i]) >> 4]);
                res.append(hexChars[0x0F & hash[i]]);
            }
            return res.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
private static void copierScriptChargement(File webInfDir, String initialDataChoice) {
        File chargementInitialDir = new File(webInfDir, "chargementInitial");
        File fichierChargement = new File(chargementInitialDir, "ScriptChargementInitial.sql");
        File fichierChargementAll = new File(chargementInitialDir, "ScriptChargementInitial-All.sql");
        File fichierChargementTypesDocument = new File(chargementInitialDir, "ScriptChargementInitial-TypesDocument.sql");
        File fichierChargementVide = new File(chargementInitialDir, "ScriptChargementInitial-Vide.sql");
        if (fichierChargement.exists()) {
            fichierChargement.delete();
        }
        File fichierUtilise = null;
        if ("all".equals(initialDataChoice)) {
            fichierUtilise = fichierChargementAll;
        } else if ("typesDocument".equals(initialDataChoice)) {
            fichierUtilise = fichierChargementTypesDocument;
        } else if ("empty".equals(initialDataChoice)) {
            fichierUtilise = fichierChargementVide;
        }
        if (fichierUtilise != null && fichierUtilise.exists()) {
            FileChannel source = null;
            FileChannel destination = null;
            try {
                source = new FileInputStream(fichierUtilise).getChannel();
                destination = new FileOutputStream(fichierChargement).getChannel();
                destination.transferFrom(source, 0, source.size());
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                if (source != null) {
                    try {
                        source.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (destination != null) {
                    try {
                        destination.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
boolean copyFileStructure(File oldFile, File newFile) {
        if (oldFile == null || newFile == null) return false;
        File searchFile = newFile;
        do {
            if (oldFile.equals(searchFile)) return false;
            searchFile = searchFile.getParentFile();
        } while (searchFile != null);
        if (oldFile.isDirectory()) {
            if (progressDialog != null) {
                progressDialog.setDetailFile(oldFile, ProgressDialog.COPY);
            }
            if (simulateOnly) {
            } else {
                if (!newFile.mkdirs()) return false;
            }
            File[] subFiles = oldFile.listFiles();
            if (subFiles != null) {
                if (progressDialog != null) {
                    progressDialog.addWorkUnits(subFiles.length);
                }
                for (int i = 0; i < subFiles.length; i++) {
                    File oldSubFile = subFiles[i];
                    File newSubFile = new File(newFile, oldSubFile.getName());
                    if (!copyFileStructure(oldSubFile, newSubFile)) return false;
                    if (progressDialog != null) {
                        progressDialog.addProgress(1);
                        if (progressDialog.isCancelled()) return false;
                    }
                }
            }
        } else {
            if (simulateOnly) {
            } else {
                FileReader in = null;
                FileWriter out = null;
                try {
                    in = new FileReader(oldFile);
                    out = new FileWriter(newFile);
                    int count;
                    while ((count = in.read()) != -1) out.write(count);
                } catch (FileNotFoundException e) {
                    return false;
                } catch (IOException e) {
                    return false;
                } finally {
                    try {
                        if (in != null) in.close();
                        if (out != null) out.close();
                    } catch (IOException e) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
public void convert(String newDocumentName, URL url) throws IOException {
        documentPath = createDirectoryStructure(this.destinationPath, newDocumentName);
        try {
            Document doc = builder.build(url.openStream());
            Element elementx = doc.getRootElement();
            convertElement(elementx);
            System.out.println("\n\n");
            XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat());
            System.out.println("as file: " + url.getFile());
            File inputFile = new File(url.getFile());
            File outputFile = new File(documentPath, renameFileExtention(inputFile, "-remaining.xml"));
            System.out.println("outputFile: " + outputFile);
            outp.output(doc, new FileOutputStream(outputFile));
        } catch (JDOMException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
protected BufferedImage handleRaremapsException() {
        if (params.uri.startsWith("http://www.raremaps.com/cgi-bin/gallery.pl/detail/")) try {
            params.uri = params.uri.replace("cgi-bin/gallery.pl/detail", "maps/medium");
            URL url = new URL(params.uri);
            URLConnection connection = url.openConnection();
            return processNewUri(connection);
        } catch (Exception e) {
        }
        return null;
    }
protected BufferedImage handleICCException() {
        if (params.uri.startsWith("http://vacani.icc.cat") || params.uri.startsWith("http://louisdl.louislibraries.org")) try {
            params.uri = params.uri.replace("cdm4/item_viewer.php", "cgi-bin/getimage.exe") + "&DMSCALE=3";
            params.uri = params.uri.replace("/u?", "cgi-bin/getimage.exe?CISOROOT=").replace(",", "&CISOPTR=") + "&DMSCALE=3";
            URL url = new URL(params.uri);
            URLConnection connection = url.openConnection();
            return processNewUri(connection);
        } catch (Exception e) {
        }
        return null;
    }
protected BufferedImage handleFirenzeException() {
        if (params.uri.indexOf("bncf.firenze.sbn.it") != -1) try {
            params.uri = params.uri.replace("http://opac.bncf.firenze.sbn.it/mdigit/jsp/mdigit.jsp?idr", "http://teca.bncf.firenze.sbn.it/TecaViewer/index.jsp?RisIdr");
            URLConnection connection = new URL(params.uri).openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String url = null;
            params.uri = "addPage('http://opac.bncf.firenze.sbn.it/php/xlimage/XLImageRV.php";
            while ((url = reader.readLine()) != null) {
                int index = url.indexOf(params.uri);
                if (index != -1) {
                    url = url.substring(url.indexOf("'") + 1, url.lastIndexOf("'"));
                    break;
                }
            }
            connection = new URL(url).openConnection();
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            params.uri = "<input type=\"image\" border=\"0\" name=\"tpos\" width=\"";
            while ((url = reader.readLine()) != null) {
                int index = url.indexOf(params.uri);
                if (index != -1) {
                    url = url.substring(url.indexOf(" src=\"") + 6, url.lastIndexOf("\" alt=\"")).replace("&z=2", "&z=32").replace("&z=4", "&z=64").replace("&z=8", "&z=128");
                    break;
                }
            }
            if (url != null) {
                connection = new URL(url).openConnection();
                return processNewUri(connection);
            }
        } catch (Exception e) {
        }
        return null;
    }
protected BufferedImage handleGMUException() {
        if (params.uri.startsWith("http://mars.gmu.edu:8080")) try {
            URLConnection connection = new URL(params.uri).openConnection();
            int index = params.uri.lastIndexOf("?");
            params.uri = "<img class=\"itemthumb\" src=\"";
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String url = null;
            while ((url = reader.readLine()) != null) {
                index = url.indexOf(params.uri);
                if (index != -1) {
                    url = "http://mars.gmu.edu:8080" + url.substring(index + 28);
                    url = url.substring(0, url.indexOf("\" alt=\""));
                    break;
                }
            }
            if (url != null) {
                connection = new URL(url).openConnection();
                return processNewUri(connection);
            }
        } catch (Exception e) {
        }
        return null;
    }
protected BufferedImage handleFCLAException() {
        if (params.uri.startsWith("http://image11.fcla.edu/cgi")) try {
            params.uri = params.uri.substring(params.uri.indexOf("q1=") + 3);
            params.uri = params.uri.substring(0, params.uri.indexOf("&"));
            params.uri = "http://image11.fcla.edu/m/map/thumb/" + params.uri.substring(params.uri.length() - 3, params.uri.length() - 2) + "/" + params.uri.substring(params.uri.length() - 2, params.uri.length() - 1) + "/" + params.uri.substring(params.uri.length() - 1, params.uri.length()) + "/" + params.uri + ".jpg";
            URL url = new URL(params.uri);
            URLConnection connection = url.openConnection();
            return processNewUri(connection);
        } catch (Exception e) {
        }
        return null;
    }
protected BufferedImage handleBNException() {
        if (params.uri.startsWith("http://purl.pt/")) try {
            URLConnection connection = new URL(params.uri).openConnection();
            if (params.uri.endsWith("/")) params.uri = params.uri.substring(0, params.uri.length() - 1);
            int index = params.uri.lastIndexOf("/");
            params.uri = "http://purl.pt/homepage/" + params.uri.substring(index + 1) + "/" + params.uri.substring(index + 1);
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String url = null;
            while ((url = reader.readLine()) != null) {
                index = url.indexOf(params.uri);
                if (index != -1) {
                    url = url.substring(index);
                    url = url.substring(0, url.indexOf("\""));
                    break;
                }
            }
            if (url != null) {
                connection = new URL(url).openConnection();
                return processNewUri(connection);
            }
        } catch (Exception e) {
        }
        return null;
    }
protected BufferedImage handleNLIBException() {
        if (params.uri.startsWith("http://digar.nlib.ee/otsing/") || params.uri.startsWith("http://digar.nlib.ee/show")) try {
            String url = "http://digar.nlib.ee/gmap/nd" + params.uri.substring(params.uri.indexOf(":") + 1, params.uri.lastIndexOf("&")) + "-tiles/z0x0y0.jpeg";
            URLConnection connection = new URL(url).openConnection();
            return processNewUri(connection);
        } catch (Exception e) {
            try {
                if (params.uri.startsWith("http://digar.nlib.ee/show")) params.uri = "http://digar.nlib.ee/otsing/?pid=" + params.uri.substring(params.uri.lastIndexOf("/") + 1) + "&show";
                URLConnection connection = new URL(params.uri).openConnection();
                String url = params.uri;
                if (url.endsWith("&show")) url = url.substring(0, url.length() - 5);
                int index = url.lastIndexOf("?");
                url = "stream" + url.substring(index);
                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String aux = null;
                while ((aux = reader.readLine()) != null) {
                    index = aux.indexOf(url);
                    if (index != -1) {
                        url = "http://digar.nlib.ee/otsing/" + aux.substring(index);
                        index = url.indexOf('>');
                        if (index == -1) index = url.indexOf("\"");
                        url = url.substring(0, index);
                        break;
                    }
                }
                connection = new URL(url).openConnection();
                return processNewUri(connection);
            } catch (Exception e2) {
            }
        }
        return null;
    }
protected BufferedImage handleKBRException() {
        if (params.uri.startsWith("http://mara.kbr.be/kbrImage/CM/") || params.uri.startsWith("http://mara.kbr.be/kbrImage/maps/") || params.uri.startsWith("http://opteron2.kbr.be/kp/viewer/")) try {
            URLConnection connection = new URL(params.uri).openConnection();
            String url = "get_image.php?intId=";
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String aux = null;
            while ((aux = reader.readLine()) != null) {
                if (aux.indexOf(url) != -1) {
                    aux = aux.substring(aux.indexOf(url));
                    url = "http://mara.kbr.be/kbrImage/" + aux.substring(0, aux.indexOf("\""));
                    break;
                }
            }
            connection = new URL(url).openConnection();
            return processNewUri(connection);
        } catch (Exception e) {
            try {
                String url = "http://mara.kbr.be/xlimages/maps/thumbnails" + params.uri.substring(params.uri.lastIndexOf("/")).replace(".imgf", ".jpg");
                if (url != null) {
                    URLConnection connection = new URL(url).openConnection();
                    return processNewUri(connection);
                }
            } catch (Exception e2) {
            }
        }
        return null;
    }
private String createCSVFile(String fileName) throws FileNotFoundException, IOException {
        String csvFile = fileName + ".csv";
        BufferedReader buf = new BufferedReader(new FileReader(fileName));
        BufferedWriter out = new BufferedWriter(new FileWriter(csvFile));
        String line;
        while ((line = buf.readLine()) != null) out.write(line + "\n");
        buf.close();
        out.close();
        return csvFile;
    }
private List<String> readDescriptor(URL url) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            List<String> lines = new ArrayList<String>();
            String line = reader.readLine();
            while (line != null) {
                line = line.trim();
                if (line.length() > 0 && !line.startsWith("#")) lines.add(line);
                line = reader.readLine();
            }
            return lines;
        } catch (IOException e) {
            throw new ExtensionException("Failed to read extension descriptor '%s'", e).withArgs(url);
        } finally {
            IoUtil.closeQuietly(reader);
        }
    }
public void copyFile(File sourceFile, File destFile) throws IOException {
        Log.level3("Copying " + sourceFile.getPath() + " to " + destFile.getPath());
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
        }
        if (destination != null) {
            destination.close();
        }
    }
private static void recurseFiles(File root, File file, ZipArchiveOutputStream zaos, boolean absolute) throws IOException {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file2 : files) {
                recurseFiles(root, file2, zaos, absolute);
            }
        } else if ((!file.getName().endsWith(".zip")) && (!file.getName().endsWith(".ZIP"))) {
            String filename = null;
            if (absolute) {
                filename = file.getAbsolutePath().substring(root.getAbsolutePath().length());
            } else {
                filename = file.getName();
            }
            ZipArchiveEntry zae = new ZipArchiveEntry(filename);
            zae.setSize(file.length());
            zaos.putArchiveEntry(zae);
            FileInputStream fis = new FileInputStream(file);
            IOUtils.copy(fis, zaos);
            zaos.closeArchiveEntry();
        }
    }