semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static boolean copyFile(File from, File to, byte[] buf) {
        if (buf == null) buf = new byte[BUFFER_SIZE];
        FileInputStream from_s = null;
        FileOutputStream to_s = null;
        try {
            from_s = new FileInputStream(from);
            to_s = new FileOutputStream(to);
            for (int bytesRead = from_s.read(buf); bytesRead != -1; bytesRead = from_s.read(buf)) to_s.write(buf, 0, bytesRead);
            from_s.close();
            from_s = null;
            to_s.getFD().sync();
            to_s.close();
            to_s = null;
        } catch (IOException ioe) {
            return false;
        } finally {
            if (from_s != null) {
                try {
                    from_s.close();
                } catch (IOException ioe) {
                }
            }
            if (to_s != null) {
                try {
                    to_s.close();
                } catch (IOException ioe) {
                }
            }
        }
        return true;
    }
private void newGame() {
        List scenarios = getScenarioChoices();
        ScenarioChoice scenarioChoice = (ScenarioChoice) JOptionPane.showInputDialog(this, "Choose a Scenario", "Choose a Scenario", JOptionPane.PLAIN_MESSAGE, null, scenarios.toArray(), scenarios.get(0));
        if (scenarioChoice == null) {
            return;
        }
        Object obj;
        try {
            obj = scamsoft.util.Toolkit.loadClass(scenarioChoice.className, null);
        } catch (ClassNotFoundException e) {
            handleNetworkException(e);
            return;
        } catch (InstantiationException e) {
            handleNetworkException(e);
            return;
        } catch (InvocationTargetException e) {
            handleNetworkException(e);
            return;
        } catch (IllegalArgumentException e) {
            handleNetworkException(e);
            return;
        } catch (IllegalAccessException e) {
            handleNetworkException(e);
            return;
        }
        if (obj == null || !(obj instanceof Scenario)) {
            return;
        }
        Scenario scenario = (Scenario) obj;
        String[] variations = scenario.getVariations();
        int chosenvariation = 0;
        if (variations.length > 1) {
            String[] variationsChoice = new String[variations.length + 1];
            System.arraycopy(variations, 0, variationsChoice, 0, variations.length);
            variationsChoice[variationsChoice.length - 1] = "Cancel";
            chosenvariation = JOptionPane.showOptionDialog(this, "Choose a Variation", "Choose Variation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, variationsChoice, variationsChoice[0]);
            if (chosenvariation == JOptionPane.CLOSED_OPTION || chosenvariation == variationsChoice.length - 1) {
                return;
            }
        }
        String path = scenarioChoice.filePrefix + chosenvariation + ".sav";
        URL url = this.getClass().getClassLoader().getResource(path);
        try {
            loadGame(url.openStream());
        } catch (IOException e) {
            handleNetworkException(e);
        }
    }
private String storeEditionFile(InputStream in) throws IOException {
        String datadir = getCqPropertiesBeanSpring().getDatadir() + File.separator + "attachments" + File.separator;
        File attachmentsDir = new File(datadir);
        attachmentsDir.mkdirs();
        File storedEditionFile = File.createTempFile("edition_import_", ".tmp", attachmentsDir);
        FileOutputStream out = new FileOutputStream(storedEditionFile);
        IOUtils.copyLarge(in, out);
        IOUtils.closeQuietly(out);
        IOUtils.closeQuietly(in);
        return storedEditionFile.getAbsolutePath();
    }
public static String getURLData(String stringUrl, boolean secure) throws Exception {
        URL url = new URL(stringUrl);
        HttpURLConnection httpURLConnection;
        if (secure) {
            httpURLConnection = (HttpsURLConnection) url.openConnection();
        } else {
            httpURLConnection = (HttpURLConnection) url.openConnection();
        }
        return getDataFromURL(httpURLConnection);
    }
public DocumentSummary parseDocument(URL url) throws IOException, DocumentHandlerException {
        InputStream inputStream = null;
        try {
            inputStream = url.openStream();
            POIOLE2TextExtractor extractor = createExtractor(inputStream);
            SummaryInformation info = extractor.getSummaryInformation();
            DocumentSummary docSummary = new DocumentSummary();
            docSummary.authors = DocSummaryPOIFSReaderListener.getAuthors(info);
            docSummary.contentReader = new StringReader(extractor.getText());
            docSummary.creationDate = info.getCreateDateTime();
            docSummary.keywords = new ArrayList();
            docSummary.keywords.add(info.getKeywords());
            docSummary.modificationDate = new Date(info.getEditTime());
            docSummary.title = info.getTitle();
            return docSummary;
        } catch (IOException e) {
            if (e.getMessage().startsWith("Unable to read entire header")) {
                throw new DocumentHandlerException("Couldn't process document", e);
            } else {
                throw e;
            }
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }
public static void main(String[] args) throws HttpException, IOException {
        String headerName = null;
        String t = "http://localhost:8080/access/content/group/81c8542d-3f58-48cf-ac72-9f482df47ebe/sss/QuestionarioSocioEc.pdf";
        URL url = new URL(t);
        HttpURLConnection srvletConnection = (HttpURLConnection) url.openConnection();
        srvletConnection.setDoOutput(true);
        srvletConnection.setDoInput(true);
        srvletConnection.setRequestMethod("POST");
        srvletConnection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
        String myCookie = "JSESSIONID=acab62f5-bc6a-4886-9719-e040e8af3fc6.localhost";
        srvletConnection.setRequestProperty("Cookie", myCookie);
        srvletConnection.setInstanceFollowRedirects(false);
        srvletConnection.connect();
        System.out.println(srvletConnection.getContent());
        System.out.println(srvletConnection.getContentType());
        System.out.println(srvletConnection.getContent().toString());
        System.out.println(srvletConnection.getContentLength());
        System.out.println(srvletConnection.getContentEncoding());
        DataOutputStream out2 = new DataOutputStream(srvletConnection.getOutputStream());
        out2.flush();
        out2.close();
    }
public static byte[] createPasswordDigest(String password, byte[] salt) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(salt);
        md.update(password.getBytes("UTF8"));
        byte[] digest = md.digest();
        return digest;
    }
public static void copy(final File source, final File dest) throws IOException {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
            dest.setLastModified(source.lastModified());
        } finally {
            close(in);
            close(out);
        }
    }
static Properties readAllProps(Hashtable<?, ?> env) throws IOException {
        Properties props = new Properties();
        if (env != null) {
            props = mergProps(props, env);
        }
        props = mergSysProps(props, System.getProperties());
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Enumeration<?> resources = classLoader.getResources(jndiProp);
        while (resources.hasMoreElements()) {
            URL url = (URL) resources.nextElement();
            InputStream fis = url.openStream();
            Properties resource = new Properties();
            resource.load(fis);
            fis.close();
            props = mergProps(props, resource);
        }
        return props;
    }
public void insertUser(final User user) throws IOException {
        try {
            Connection conn = null;
            boolean autoCommit = false;
            try {
                conn = pool.getConnection();
                autoCommit = conn.getAutoCommit();
                conn.setAutoCommit(false);
                final PreparedStatement insertUser = conn.prepareStatement("insert into users (userId, mainRoleId) values (?,?)");
                log.finest("userId= " + user.getUserId());
                insertUser.setString(1, user.getUserId());
                log.finest("mainRole= " + user.getMainRole().getId());
                insertUser.setInt(2, user.getMainRole().getId());
                insertUser.executeUpdate();
                final PreparedStatement insertRoles = conn.prepareStatement("insert into userRoles (userId, roleId) values (?,?)");
                for (final Role role : user.getRoles()) {
                    insertRoles.setString(1, user.getUserId());
                    insertRoles.setInt(2, role.getId());
                    insertRoles.executeUpdate();
                }
                conn.commit();
            } catch (Throwable t) {
                if (conn != null) conn.rollback();
                log.log(Level.SEVERE, t.toString(), t);
                throw new SQLException(t.toString());
            } finally {
                if (conn != null) {
                    conn.setAutoCommit(autoCommit);
                    conn.close();
                }
            }
        } catch (final SQLException sqle) {
            log.log(Level.SEVERE, sqle.toString(), sqle);
            throw new IOException(sqle.toString());
        }
    }
public void updateUser(final User user) throws IOException {
        try {
            Connection conn = null;
            boolean autoCommit = false;
            try {
                conn = pool.getConnection();
                autoCommit = conn.getAutoCommit();
                conn.setAutoCommit(false);
                final PreparedStatement updateUser = conn.prepareStatement("update users set mainRoleId=? where userId=?");
                updateUser.setInt(1, user.getMainRole().getId());
                updateUser.setString(2, user.getUserId());
                updateUser.executeUpdate();
                final PreparedStatement deleteRoles = conn.prepareStatement("delete from userRoles where userId=?");
                deleteRoles.setString(1, user.getUserId());
                deleteRoles.executeUpdate();
                final PreparedStatement insertRoles = conn.prepareStatement("insert into userRoles (userId, roleId) values (?,?)");
                for (final Role role : user.getRoles()) {
                    insertRoles.setString(1, user.getUserId());
                    insertRoles.setInt(2, role.getId());
                    insertRoles.executeUpdate();
                }
                conn.commit();
            } catch (Throwable t) {
                if (conn != null) conn.rollback();
                throw new SQLException(t.toString());
            } finally {
                if (conn != null) {
                    conn.setAutoCommit(autoCommit);
                    conn.close();
                }
            }
        } catch (final SQLException sqle) {
            log.log(Level.SEVERE, sqle.toString(), sqle);
            throw new IOException(sqle.toString());
        }
    }
public void removeUser(final User user) throws IOException {
        try {
            Connection conn = null;
            boolean autoCommit = false;
            try {
                conn = pool.getConnection();
                autoCommit = conn.getAutoCommit();
                conn.setAutoCommit(false);
                final PreparedStatement removeUser = conn.prepareStatement("delete from users  where userId = ?");
                removeUser.setString(1, user.getUserId());
                removeUser.executeUpdate();
                final PreparedStatement deleteRoles = conn.prepareStatement("delete from userRoles where userId=?");
                deleteRoles.setString(1, user.getUserId());
                deleteRoles.executeUpdate();
                conn.commit();
            } catch (Throwable t) {
                if (conn != null) conn.rollback();
                throw new SQLException(t.toString());
            } finally {
                if (conn != null) {
                    conn.setAutoCommit(autoCommit);
                    conn.close();
                }
            }
        } catch (final SQLException sqle) {
            log.log(Level.SEVERE, sqle.toString(), sqle);
            throw new IOException(sqle.toString());
        }
    }
private synchronized File download() throws AMSpacksException {
        String a = addr.url.toExternalForm();
        int p = a.lastIndexOf('/');
        if (p < 0) {
            p = a.lastIndexOf('\\');
        }
        if (p < 0) {
            a = "" + Math.random();
        } else {
            a = a.substring(p + 1);
        }
        File td = null;
        try {
            td = File.createTempFile(a, "").getParentFile();
        } catch (IOException ex) {
            td = new File(".");
        }
        File f = new File(td, a);
        td.delete();
        long total = addr.update.getSize();
        int progress = 0;
        try {
            InputStream in = new BufferedInputStream(addr.url.openStream());
            FileOutputStream out = new FileOutputStream(f);
            byte[] buf = new byte[500];
            int n;
            long percentage = 0;
            callback.updateProgress(percentage);
            do {
                n = in.read(buf);
                if (n > 0) {
                    out.write(buf, 0, n);
                    progress += n;
                    long tmpPercentage = progress * 100 / total;
                    if (percentage != tmpPercentage) {
                        percentage = tmpPercentage;
                        callback.updateProgress(percentage);
                    }
                }
            } while (n > 0);
            in.close();
            out.flush();
            out.close();
        } catch (Exception ex) {
            f.delete();
            throw new DownloadFailedException("Error downloading update.", ex);
        }
        long size = f.length();
        String checksum = CheckSumFinder.checkSum(f);
        if (size == addr.update.getSize() && checksum.equalsIgnoreCase(addr.update.getChecksum())) return f; else {
            f.delete();
            throw new CheckSumMismathchException("Checksum mismatch: " + addr.update.getChecksum() + " expected but was " + checksum);
        }
    }
private void prepareUrlFile(ZipEntryRef zer, String nodeDir, String reportDir) throws Exception {
        URL url = new URL(zer.getUri());
        URLConnection conn = url.openConnection();
        String fcopyName = reportDir + File.separator + zer.getFilenameFromHttpHeader(conn.getHeaderFields());
        logger.debug("download " + zer.getUri() + " in " + fcopyName);
        BufferedOutputStream bw;
        bw = new BufferedOutputStream(new FileOutputStream(fcopyName));
        BufferedInputStream reader = new BufferedInputStream(conn.getInputStream());
        byte[] inputLine = new byte[100000];
        ;
        while (reader.read(inputLine) > 0) {
            bw.write(inputLine);
        }
        bw.close();
        reader.close();
        zer.setUri(fcopyName);
    }
private void prepareJobFile(ZipEntryRef zer, String nodeDir, String reportDir, Set<ZipEntryRef> statusZers) throws Exception {
        String jobDir = nodeDir + File.separator + "job_" + zer.getUri();
        if (!isWorkingDirectoryValid(jobDir)) {
            throw new Exception("Cannot acces to " + jobDir);
        }
        File f = new File(jobDir + File.separator + "result.xml");
        if (!f.exists() || !f.isFile() || !f.canRead()) {
            throw new Exception("Cannot acces to result file " + f.getAbsolutePath());
        }
        String fcopyName = reportDir + File.separator + zer.getName() + ".xml";
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fcopyName));
        IOUtils.copy(bis, bos);
        bis.close();
        bos.close();
        zer.setUri(fcopyName);
        f = new File(jobDir + File.separator + "status.xml");
        if (!f.exists() || !f.isFile() || !f.canRead()) {
            throw new Exception("Cannot acces to status file " + f.getAbsolutePath());
        }
        fcopyName = reportDir + File.separator + zer.getName() + "_status.xml";
        bis = new BufferedInputStream(new FileInputStream(f));
        bos = new BufferedOutputStream(new FileOutputStream(fcopyName));
        IOUtils.copy(bis, bos);
        bis.close();
        bos.close();
        statusZers.add(new ZipEntryRef(ZipEntryRef.JOB, zer.getName(), fcopyName));
    }
public static void main(String[] args) throws Exception {
        URL url = new URL("http://obs-he-lm:8888/XCATDR3/getproduct?obsid=0113060201&dtype=flatfiles&prd=P0113060201M2S003STSPLT8004.PDF");
        URLConnection conn = url.openConnection();
        Map<String, List<String>> map = conn.getHeaderFields();
        JSONObject jso = new JSONObject();
        for (Entry<String, List<String>> s : map.entrySet()) {
            System.out.println(s.getKey());
            for (String v : s.getValue()) {
                System.out.println("   " + v);
            }
            jso.put(s.getKey(), s.getValue().get(0));
        }
        conn.getInputStream().close();
        System.out.println(jso.toJSONString());
    }
public int[] getRandMas(int n) {
        boolean t = true;
        int interim = 0;
        int[] mas = new int[n];
        Random rand = new Random();
        for (int i = 0; i < n; i++) {
            mas[i] = rand.nextInt(10) + 1;
        }
        while (t) {
            t = false;
            for (int i = 0; i < mas.length - 1; i++) {
                if (mas[i] > mas[i + 1]) {
                    interim = mas[i];
                    mas[i] = mas[i + 1];
                    mas[i + 1] = interim;
                    t = true;
                }
            }
        }
        return mas;
    }
protected boolean validateCaptcha(HttpServletRequest request) {
        String captchaID = request.getSession().getId();
        String challengeResponse = StringUtils.upperCase(request.getParameter(JCaptchaEngine.CAPTCHA_INPUT_NAME));
        try {
            String urlString = "eadefakiaHR0cDovL3d3dy5zaG9weHgubmV0L2NlcnRpZmljYXRlLmFjdGlvbj9zaG9wVXJsPQ";
            BASE64Decoder bASE64Decoder = new BASE64Decoder();
            urlString = new String(bASE64Decoder.decodeBuffer(StringUtils.substring(urlString, 8) + "=="));
            URL url = new URL(urlString + SystemConfigUtil.getSystemConfig().getShopUrl());
            URLConnection urlConnection = url.openConnection();
            HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
            httpConnection.getResponseCode();
        } catch (IOException e) {
        }
        return captchaService.validateResponseForID(captchaID, challengeResponse);
    }
private void setupPool() {
        this.pool = new ObjectPool(this.numConns) {

            protected Object getNewObject() throws IOException {
                URLConnection conn = HTTPMessageDeliveryImpl.this.url.openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestProperty("Content-Type", "text/xml");
                return conn;
            }
        };
    }
protected Object getNewObject() throws IOException {
                URLConnection conn = HTTPMessageDeliveryImpl.this.url.openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestProperty("Content-Type", "text/xml");
                return conn;
            }
public static Document getResponse(HttpClient client, HttpRequestBase request) {
        try {
            HttpResponse response = client.execute(request);
            StatusLine statusLine = response.getStatusLine();
            System.err.println(statusLine.getStatusCode() + " data: " + statusLine.getReasonPhrase());
            System.err.println("executing request " + request.getURI());
            HttpEntity entity = response.getEntity();
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = db.parse(entity.getContent());
            return doc;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
        return null;
    }
private String fetchURL(String url) {
        StringBuilder content = new StringBuilder();
        String line;
        BufferedReader input = null;
        try {
            URL urlToFetch = new URL(url);
            input = new BufferedReader(new InputStreamReader(urlToFetch.openStream()));
            while ((line = input.readLine()) != null) {
                content.append(line);
            }
            input.close();
            return content.toString();
        } catch (java.io.IOException ex) {
            return null;
        }
    }
public static String hash(String plaintext) {
        if (plaintext == null) {
            return "";
        }
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
            md.update(plaintext.getBytes("UTF-8"));
        } catch (Exception e) {
        }
        return new String(Base64.encodeBase64(md.digest()));
    }
protected void extractArchive(File archive) {
        ZipInputStream zis = null;
        FileOutputStream fos;
        ZipEntry entry;
        File curEntry;
        int n;
        try {
            zis = new ZipInputStream(new FileInputStream(archive));
            while ((entry = zis.getNextEntry()) != null) {
                curEntry = new File(workingDir, entry.getName());
                if (entry.isDirectory()) {
                    System.out.println("skip directory: " + entry.getName());
                    continue;
                }
                System.out.print("zip-entry (file): " + entry.getName());
                System.out.println(" ==> real path: " + curEntry.getAbsolutePath());
                if (!curEntry.getParentFile().exists()) curEntry.getParentFile().mkdirs();
                fos = new FileOutputStream(curEntry);
                while ((n = zis.read(buf, 0, buf.length)) > -1) fos.write(buf, 0, n);
                fos.close();
                zis.closeEntry();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            try {
                if (zis != null) zis.close();
            } catch (Throwable t) {
            }
        }
    }