semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void main(String[] args) {
        String source, destination;
        if (args[0].toLowerCase().endsWith(".gz")) {
            source = args[0];
            destination = source.substring(0, source.length() - 3);
        } else {
            source = args[0] + ".gz";
            destination = args[0];
        }
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new GZIPInputStream(new FileInputStream(source));
            os = new FileOutputStream(destination);
            byte[] buffer = new byte[8192];
            for (int length; (length = is.read(buffer)) != -1; ) os.write(buffer, 0, length);
        } catch (IOException e) {
            System.err.println("Fehler: Kann nicht entpacken " + args[0]);
        } finally {
            if (os != null) try {
                os.close();
            } catch (IOException e) {
            }
            if (is != null) try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
public static void copy(String from_name, String to_name) throws IOException {
        File from_file = new File(from_name);
        File to_file = new File(to_name);
        if (!from_file.exists()) abort("FileCopy: no such source file: " + from_name);
        if (!from_file.isFile()) abort("FileCopy: can't copy directory: " + from_name);
        if (!from_file.canRead()) abort("FileCopy: source file is unreadable: " + from_name);
        if (to_file.isDirectory()) to_file = new File(to_file, from_file.getName());
        if (to_file.exists()) {
            if (!to_file.canWrite()) abort("FileCopy: destination file is unwriteable: " + to_name);
        } else {
            String parent = to_file.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) abort("FileCopy: destination directory doesn't exist: " + parent);
            if (dir.isFile()) abort("FileCopy: destination is not a directory: " + parent);
            if (!dir.canWrite()) abort("FileCopy: destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(from_file);
            to = new FileOutputStream(to_file);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) to.write(buffer, 0, bytes_read);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
private static HttpURLConnection sendPost(String reqUrl, Map<String, String> parameters) {
        HttpURLConnection urlConn = null;
        try {
            String params = generatorParamString(parameters);
            URL url = new URL(reqUrl);
            urlConn = (HttpURLConnection) url.openConnection();
            urlConn.setRequestMethod("POST");
            urlConn.setConnectTimeout(5000);
            urlConn.setReadTimeout(5000);
            urlConn.setDoOutput(true);
            byte[] b = params.getBytes();
            urlConn.getOutputStream().write(b, 0, b.length);
            urlConn.getOutputStream().flush();
            urlConn.getOutputStream().close();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        return urlConn;
    }
private PluginInterface getClasseJar(String arquivo) {
        URLClassLoader load;
        try {
            URL url = new URL("jar", "", "file:" + arquivo + "!/");
            JarURLConnection jar = (JarURLConnection) url.openConnection();
            Enumeration arq = jar.getJarFile().entries();
            load = new URLClassLoader(new URL[] { url });
            while (arq.hasMoreElements()) {
                Object object = arq.nextElement();
                if (object.toString().contains(".class") && !object.toString().contains("PluginInterface.class")) {
                    Class cl = load.loadClass(object.toString().replace(".class", ""));
                    pl = (PluginInterface) cl.newInstance();
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return pl;
    }
@SuppressWarnings("unchecked")
    public ProcessContext execute(ProcessContext context) throws Exception {
        List<String> urls = (List<String>) context.get(getContextKeyFileUrls(), List.class, true);
        for (String url : urls) {
            long time = System.currentTimeMillis();
            logger.info("Starting url: " + url);
            InputStream is = null;
            if (url.startsWith("http://") || url.startsWith("ftp://")) {
                is = new URL(url).openStream();
            } else {
                is = new FileInputStream(url);
            }
            String separator = (String) context.get(getContextKeySeparator(), String.class, false);
            if (separator == null) {
                separator = "\t";
            }
            String quoteCharacter = (String) context.get(getContextKeyQuoteCharacter(), String.class, false);
            DelimitedFileReader reader = new DelimitedFileReader(is, separator, quoteCharacter, true);
            Set<String> columns = reader.getColumnHeaders();
            while (reader.next()) {
                logger.debug("Starting row: " + reader.getRowNumber());
                for (String column : columns) {
                    String value = StringUtils.trimToNull(reader.get(column));
                    String key = getContextKeyPrefix() + column;
                    if (lowerCaseFirstLetterForContext && key.length() > 1) {
                        key = key.substring(0, 1).toLowerCase() + key.substring(1);
                    } else if (lowerCaseFirstLetterForContext) {
                        key = key.toLowerCase();
                    }
                    context.put(key, value);
                    logger.debug("Added key[" + key + "] value[" + value + "]");
                }
                launchWorkflow(context, null);
            }
            logger.info("Finished url [" + url + "] in " + ((System.currentTimeMillis() + 1 - time) / 1000) + " secs");
        }
        return context;
    }
private boolean copyFile(File _file1, File _file2) {
        FileInputStream fis;
        FileOutputStream fos;
        try {
            fis = new FileInputStream(_file1);
            fos = new FileOutputStream(_file2);
            FileChannel canalFuente = fis.getChannel();
            canalFuente.transferTo(0, canalFuente.size(), fos.getChannel());
            fis.close();
            fos.close();
            return true;
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
        return false;
    }
public static Board readStream(InputStream is) throws IOException {
        StringWriter stringWriter = new StringWriter();
        IOUtils.copy(is, stringWriter);
        String s = stringWriter.getBuffer().toString();
        Board board = read(s);
        return board;
    }
public static String encrypt(String passPhrase, String password) {
        String algorithm = "PBEWithMD5AndDES";
        byte[] salt = new byte[8];
        int iterations = 20;
        byte[] output = new byte[128];
        if (passPhrase == null || "".equals(passPhrase) || password == null || "".equals(password)) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "Required parameter missing");
        }
        try {
            Security.addProvider(new com.sun.crypto.provider.SunJCE());
            KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray());
            SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(algorithm);
            SecretKey secretKey = secretKeyFactory.generateSecret(keySpec);
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(passPhrase.getBytes());
            byte[] input = new byte[password.length()];
            input = password.getBytes();
            messageDigest.update(input);
            byte[] digest = messageDigest.digest();
            System.arraycopy(digest, 0, salt, 0, 8);
            AlgorithmParameterSpec algorithmParameterSpec = new PBEParameterSpec(salt, iterations);
            Cipher cipher = Cipher.getInstance(algorithm);
            int mode = Cipher.ENCRYPT_MODE;
            cipher.init(mode, secretKey, algorithmParameterSpec);
            output = cipher.doFinal(input);
        } catch (NoSuchAlgorithmException e) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "Algorithm not found", e);
        } catch (InvalidAlgorithmParameterException e) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "nvalidAlgorithmParameter", e);
        } catch (InvalidKeySpecException e) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "InvalidKeySpec", e);
        } catch (InvalidKeyException e) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "InvalidKey", e);
        } catch (NoSuchPaddingException e) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "NoSuchPadding", e);
        } catch (BadPaddingException e) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "BadPadding", e);
        } catch (IllegalBlockSizeException e) {
            throw new GeneralException(PassPhraseCrypto.class, "encrypt", "IllegalBlockSize", e);
        }
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < output.length; i++) {
            result.append(Byte.toString(output[i]));
        }
        return result.toString();
    }
private void load() throws SQLException {
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = FidoDataSource.getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            clearTables(stmt);
            stmt.executeQuery("select setval('objects_objectid_seq', 1000)");
            stmt.executeQuery("select setval('instructions_instructionid_seq', 1)");
            stmt.executeQuery("select setval('transactions_transactionid_seq', 1)");
            stmt.executeQuery("select setval('verbtransactions_verbid_seq', 1)");
            stmt.executeUpdate("update SystemProperties set value = 'Minimal Data' where name = 'DB Data Version'");
            conn.commit();
        } catch (SQLException e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        }
    }
void shutdown(final boolean unexpected) {
        if (unexpected) {
            log.warn("S H U T D O W N   ---   received unexpected shutdown request.");
        } else {
            log.info("S H U T D O W N   ---   start regular shutdown.");
        }
        if (this.uncaughtException != null) {
            log.warn("Shutdown probably caused by the following Exception.", this.uncaughtException);
        }
        log.error("check if we need the controler listener infrastructure");
        if (this.dumpDataAtEnd) {
            new PopulationWriter(this.population, this.network).write(this.controlerIO.getOutputFilename(FILENAME_POPULATION));
            new NetworkWriter(this.network).write(this.controlerIO.getOutputFilename(FILENAME_NETWORK));
            new ConfigWriter(this.config).write(this.controlerIO.getOutputFilename(FILENAME_CONFIG));
            if (!unexpected && this.getConfig().vspExperimental().isWritingOutputEvents()) {
                File toFile = new File(this.controlerIO.getOutputFilename("output_events.xml.gz"));
                File fromFile = new File(this.controlerIO.getIterationFilename(this.getLastIteration(), "events.xml.gz"));
                IOUtils.copyFile(fromFile, toFile);
            }
        }
        if (unexpected) {
            log.info("S H U T D O W N   ---   unexpected shutdown request completed.");
        } else {
            log.info("S H U T D O W N   ---   regular shutdown completed.");
        }
        try {
            Runtime.getRuntime().removeShutdownHook(this.shutdownHook);
        } catch (IllegalStateException e) {
            log.info("Cannot remove shutdown hook. " + e.getMessage());
        }
        this.shutdownHook = null;
        this.collectLogMessagesAppender = null;
        IOUtils.closeOutputDirLogging();
    }
public static String load(String id) {
        String xml = "";
        if (id.length() < 5) return "";
        try {
            working = true;
            URL url = new URL("http://pastebin.com/download.php?i=" + id);
            URLConnection conn = url.openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            xml = "";
            String str;
            while ((str = reader.readLine()) != null) {
                xml += str;
            }
            reader.close();
            working = false;
            return xml.toString();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, " Load error");
        }
        working = false;
        return xml;
    }
public static void main(String[] argv) throws IOException {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        ;
        try {
            session.beginTransaction();
            Properties cfg = new Properties();
            URL url = SVM.class.getClassLoader().getResource(CFG_FILE);
            cfg.load(url.openStream());
            int runMode = Integer.valueOf(cfg.getProperty(KEY_RUN_MODE));
            switch(runMode) {
                case RUN_OPT:
                    new SVM().optimizeParameters(cfg);
                    break;
                case RUN_PREDICT:
                    new SVM().trainAndPredict(cfg);
                    break;
                case RUN_OPT_AND_PREDICT:
                    break;
            }
            session.getTransaction().commit();
        } catch (HibernateException he) {
            session.getTransaction().rollback();
            logger.error("Database error.", he);
            session.close();
        }
    }
@Test
    public void test01_ok_failed_500() throws Exception {
        DefaultHttpClient client = new DefaultHttpClient();
        try {
            HttpPost post = new HttpPost(chartURL);
            HttpResponse response = client.execute(post);
            assertEquals("failed code for ", 500, response.getStatusLine().getStatusCode());
        } finally {
            client.getConnectionManager().shutdown();
        }
    }
@Test
    public void test02_ok() throws Exception {
        DefaultHttpClient client = new DefaultHttpClient();
        try {
            HttpPost post = new HttpPost(chartURL);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("ws", "getDomainEvolution"));
            nameValuePairs.add(new BasicNameValuePair("chartTitle", "test"));
            nameValuePairs.add(new BasicNameValuePair("type", "chart"));
            nameValuePairs.add(new BasicNameValuePair("firstDate", "20111124"));
            nameValuePairs.add(new BasicNameValuePair("lastDate", "20111125"));
            nameValuePairs.add(new BasicNameValuePair("wsParams", "type,counting,protocol,unit,proxy,domain,timeScale,period"));
            nameValuePairs.add(new BasicNameValuePair("wsParamsValues", "chart,volume,all,hits,all,google.com,day,360"));
            nameValuePairs.add(new BasicNameValuePair("serieTitle", "serie"));
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = client.execute(post);
            HttpEntity entity = response.getEntity();
            assertNotNull(entity);
            InputStream instream = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
            System.out.println(reader.readLine());
            instream.close();
            assertEquals("error :" + response.getStatusLine(), 200, response.getStatusLine().getStatusCode());
        } finally {
            client.getConnectionManager().shutdown();
        }
    }
public FileReader(String filePath, Configuration aConfiguration) throws IOException {
        file = new File(URLDecoder.decode(filePath, "UTF-8")).getCanonicalFile();
        readerConf = aConfiguration;
        if (file.isDirectory()) {
            File indexFile = new File(file, "index.php");
            File indexFile_1 = new File(file, "index.html");
            if (indexFile.exists() && !indexFile.isDirectory()) {
                file = indexFile;
            } else if (indexFile_1.exists() && !indexFile_1.isDirectory()) {
                file = indexFile_1;
            } else {
                if (!readerConf.getOption("showFolders").equals("Yes")) {
                    makeErrorPage(503, "Permision denied");
                } else {
                    FileOutputStream out = new FileOutputStream(readerConf.getOption("wwwPath") + "/temp/temp.php");
                    File[] files = file.listFiles();
                    makeHeader(200, -1, new Date(System.currentTimeMillis()).toString(), "text/html");
                    String title = "Index of " + file;
                    out.write(("<html><head><title>" + title + "</title></head><body><h3>Index of " + file + "</h3><p>\n").getBytes());
                    for (int i = 0; i < files.length; i++) {
                        file = files[i];
                        String filename = file.getName();
                        String description = "";
                        if (file.isDirectory()) {
                            description = "&lt;DIR&gt;";
                        }
                        out.write(("<a href=\"" + file.getPath().substring(readerConf.getOption("wwwPath").length()) + "\">" + filename + "</a> " + description + "<br>\n").getBytes());
                    }
                    out.write(("</p><hr><p>yawwwserwer</p></body><html>").getBytes());
                    file = new File(URLDecoder.decode(readerConf.getOption("wwwPath") + "/temp/temp.php", "UTF-8")).getCanonicalFile();
                }
            }
        } else if (!file.exists()) {
            makeErrorPage(404, "File Not Found.");
        } else if (getExtension() == ".exe" || getExtension().contains(".py")) {
            FileOutputStream out = new FileOutputStream(readerConf.getOption("wwwPath") + "/temp/temp.php");
            out.write((runCommand(filePath)).getBytes());
            file = new File(URLDecoder.decode(readerConf.getOption("wwwPath") + "/temp/temp.php", "UTF-8")).getCanonicalFile();
        } else {
            System.out.println(getExtension());
            makeHeader(200, file.length(), new Date(file.lastModified()).toString(), TYPES.get(getExtension()).toString());
        }
        System.out.println(file);
    }
public static String getExternalIPAddress() {
        String address = null;
        URL url = null;
        try {
            url = new URL("http://checkip.dyndns.org/");
            URLConnection connection = (URLConnection) url.openConnection();
            BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
            int i;
            while ((i = in.read()) != -1) {
                address = address + (char) i;
            }
            in.close();
            address = address.substring(address.indexOf(": ") + 2);
            address = address.substring(0, address.indexOf("</body>"));
        } catch (Exception e) {
            return null;
        }
        return address;
    }
public void writeData(String name, int items, int mzmin, int mzmax, long tstart, long tdelta, int[] peaks) {
        PrintWriter file = getWriter(name + ".txt");
        file.print("Filename\t");
        file.print("Date\t");
        file.print("Acquisition #\t");
        file.print("�m Diameter\t");
        for (int i = mzmin; i <= mzmax; i++) file.print(i + "\t");
        file.println();
        int nothing = 0;
        String fileLoc = "C:/abcd/" + name + ".txt\t";
        Date tempDate;
        for (int i = 0; i < items; i++) {
            tempDate = new Date(tstart);
            tstart += tdelta;
            file.print(fileLoc);
            file.print(dateFormat.format(tempDate) + "\t");
            file.print(i + 1 + "\t");
            double t = (double) (i) / 10;
            file.print(t + "\t");
            boolean peaked = false;
            for (int k = mzmin; k <= mzmax; k++) {
                for (int j = 0; j < peaks.length && !peaked; j++) {
                    if (k == peaks[j]) {
                        file.print(peakVals[j % peakVals.length] + "\t");
                        peaked = true;
                    }
                }
                if (!peaked) {
                    if (k == mzmax) file.print(nothing); else file.print(nothing + "\t");
                }
                peaked = false;
            }
            file.println();
        }
        try {
            Scanner test = new Scanner(f);
            while (test.hasNext()) {
                System.out.println(test.nextLine());
            }
            System.out.println("test");
        } catch (Exception e) {
        }
        file.close();
    }
public Image storeImage(String title, String pathToImage, Map<String, Object> additionalProperties) {
        File collectionFolder = ProjectManager.getInstance().getFolder(PropertyHandler.getInstance().getProperty("_default_collection_name"));
        File imageFile = new File(pathToImage);
        String filename = "";
        String format = "";
        File copiedImageFile;
        while (true) {
            filename = "image" + UUID.randomUUID().hashCode();
            if (!DbEntryProvider.INSTANCE.idExists(filename)) {
                Path path = new Path(pathToImage);
                format = path.getFileExtension();
                copiedImageFile = new File(collectionFolder.getAbsolutePath() + File.separator + filename + "." + format);
                if (!copiedImageFile.exists()) break;
            }
        }
        try {
            copiedImageFile.createNewFile();
        } catch (IOException e1) {
            ExceptionHandlingService.INSTANCE.handleException(e1);
            return null;
        }
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {
            in = new BufferedInputStream(new FileInputStream(imageFile), 4096);
            out = new BufferedOutputStream(new FileOutputStream(copiedImageFile), 4096);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            ExceptionHandlingService.INSTANCE.handleException(e);
            return null;
        } catch (IOException e) {
            ExceptionHandlingService.INSTANCE.handleException(e);
            return null;
        }
        Image image = new ImageImpl();
        image.setId(filename);
        image.setFormat(format);
        image.setEntryDate(new Date());
        image.setTitle(title);
        image.setAdditionalProperties(additionalProperties);
        boolean success = DbEntryProvider.INSTANCE.storeNewImage(image);
        if (success) return image;
        return null;
    }