semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void Load(String fname) throws Exception {
        File f = null;
        try {
            if ("".equals(fname) || fname == null) throw new Exception();
            System.out.println("Loading mapfile " + fname);
        } catch (Exception e) {
            throw new Exception("File not found");
        }
        aType = null;
        fieldtype.clear();
        creatures.clear();
        aElement = new String("");
        content = null;
        Ax = -1;
        Ay = -1;
        aTemplate = -1;
        SAXParserFactory factory = SAXParserFactory.newInstance();
        data_read = 0;
        URL url = this.game.mainClass.getClassLoader().getResource(fname);
        if (url == null) {
            throw new Exception("Can't load map from : " + fname);
        }
        try {
            SAXParser parser = factory.newSAXParser();
            parser.parse(url.openStream(), this);
        } catch (Exception e) {
            System.out.println("Can't open XML : " + e);
        }
        for (int i = 0; i < fieldtype.size(); i++) {
            System.out.println((MapField) fieldtype.get(i));
        }
        game.player.setpos(start_x, start_y);
        System.out.println("Player starting position set");
        start_x = -1;
        start_y = -1;
        System.out.println("Map \"" + fname + "\" loaded");
    }
public static boolean copyFileChannel(final File _fileFrom, final File _fileTo, final boolean _append) {
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;
        try {
            srcChannel = new FileInputStream(_fileFrom).getChannel();
            dstChannel = new FileOutputStream(_fileTo, _append).getChannel();
            if (_append) {
                dstChannel.transferFrom(srcChannel, dstChannel.size(), srcChannel.size());
            } else {
                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            }
            srcChannel.close();
            dstChannel.close();
        } catch (final IOException e) {
            return false;
        } finally {
            try {
                if (srcChannel != null) {
                    srcChannel.close();
                }
            } catch (final IOException _evt) {
                FuLog.error(_evt);
            }
            try {
                if (dstChannel != null) {
                    dstChannel.close();
                }
            } catch (final IOException _evt) {
                FuLog.error(_evt);
            }
        }
        return true;
    }
public int print(String type, String url, String attrs) throws PrinterException {
        try {
            return print(type, (new URL(url)).openStream(), attrs);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PrinterException(e);
        }
    }
public void execute() throws InstallerException {
        try {
            SQLCommand sqlCommand = new SQLCommand(connectionInfo);
            connection = sqlCommand.getConnection();
            connection.setAutoCommit(false);
            sqlStatement = connection.createStatement();
            double size = (double) statements.size();
            for (String statement : statements) {
                sqlStatement.executeUpdate(statement);
                setCompletedPercentage(getCompletedPercentage() + (1 / size));
            }
            connection.commit();
        } catch (SQLException e) {
            try {
                connection.rollback();
            } catch (SQLException e1) {
                throw new InstallerException(InstallerException.TRANSACTION_ROLLBACK_ERROR, new Object[] { e.getMessage() }, e);
            }
            throw new InstallerException(InstallerException.SQL_EXEC_EXCEPTION, new Object[] { e.getMessage() }, e);
        } catch (ClassNotFoundException e) {
            throw new InstallerException(InstallerException.DB_DRIVER_LOAD_ERROR, e);
        } finally {
            if (connection != null) {
                try {
                    sqlStatement.close();
                    connection.close();
                } catch (SQLException e) {
                }
            }
        }
    }
private String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
public boolean refreshRequired() {
        boolean status = false;
        Set<String> urls = lastModifiedDates.keySet();
        try {
            for (String urlPath : urls) {
                Long lastModifiedDate = lastModifiedDates.get(urlPath);
                URL url = new URL(urlPath);
                URLConnection connection = url.openConnection();
                connection.connect();
                long newModDate = connection.getLastModified();
                if (newModDate != lastModifiedDate) {
                    status = true;
                    break;
                }
            }
        } catch (Exception e) {
            LOG.warn("Exception while monitoring update times.", e);
            return true;
        }
        return status;
    }
public static boolean copy(File from, File to, Override override) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
        FileChannel srcChannel = null;
        FileChannel destChannel = null;
        if (override == null) override = Override.NEWER;
        switch(override) {
            case NEVER:
                if (to.isFile()) return false;
                break;
            case NEWER:
                if (to.isFile() && (from.lastModified() - LASTMODIFIED_DIFF_MILLIS) < to.lastModified()) return false;
                break;
        }
        to.getParentFile().mkdirs();
        try {
            in = new FileInputStream(from);
            out = new FileOutputStream(to);
            srcChannel = in.getChannel();
            destChannel = out.getChannel();
            long position = 0L;
            long count = srcChannel.size();
            while (position < count) {
                long chunk = Math.min(MAX_IO_CHUNK_SIZE, count - position);
                position += destChannel.transferFrom(srcChannel, position, chunk);
            }
            to.setLastModified(from.lastModified());
            return true;
        } finally {
            CommonUtils.close(srcChannel);
            CommonUtils.close(destChannel);
            CommonUtils.close(out);
            CommonUtils.close(in);
        }
    }
public static void copyFile(File src, File dest) throws IOException {
        FileInputStream fis = new FileInputStream(src);
        FileOutputStream fos = new FileOutputStream(dest);
        FileChannel channelSrc = fis.getChannel();
        FileChannel channelDest = fos.getChannel();
        channelSrc.transferTo(0, channelSrc.size(), channelDest);
        fis.close();
        fos.close();
    }
public static void fillTemplate(String sourceFileName, String targetFileName, Map<String, String> values) throws IOException {
        File targetDirectory = new File(targetFileName.substring(0, targetFileName.lastIndexOf(File.separator)));
        targetDirectory.mkdirs();
        File file = new File(sourceFileName);
        FileInputStream fis = new FileInputStream(file);
        FileChannel fc = fis.getChannel();
        int sz = (int) fc.size();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
        Charset charset = Charset.forName("ISO-8859-15");
        CharsetDecoder decoder = charset.newDecoder();
        CharBuffer cb = decoder.decode(bb);
        String inString = cb.toString();
        fis.close();
        fc.close();
        Set<String> keys = values.keySet();
        for (Object k : keys) {
            inString = inString.replace((String) k, escape(values.get(k)));
        }
        FileOutputStream fos = new FileOutputStream(targetFileName);
        PrintStream ps = new PrintStream(fos);
        ps.print(inString);
        fos.close();
    }
public static void main(String[] args) throws Exception {
        TripleDES tdes = new TripleDES();
        StreamBlockReader reader = new StreamBlockReader(new FileInputStream("D:\\testTDESENC.txt"));
        StreamBlockWriter writer = new StreamBlockWriter(new FileOutputStream("D:\\testTDESDEC.txt"));
        SingleKey key = new SingleKey(new Block(128), "");
        key = new SingleKey(new Block("01011101110000101001100111001011101000001110111101001001101101101101100000011101100100110000101100001110000001111101001101001101"), "");
        Mode mode = new ECBTripleDESMode(tdes);
        tdes.decrypt(reader, writer, key, mode);
    }
private void createNodes() {
        try {
            URL url = this.getClass().getResource("NodesFile.txt");
            InputStreamReader inReader = new InputStreamReader(url.openStream());
            BufferedReader inNodes = new BufferedReader(inReader);
            String s;
            while ((s = inNodes.readLine()) != null) {
                String label = inNodes.readLine();
                String fullText = inNodes.readLine();
                String type = inNodes.readLine();
                Node n = new Node(s, type);
                n.label = label;
                n.fullText = fullText;
                node.add(n);
            }
            inNodes.close();
            url = this.getClass().getResource("EdgesFile.txt");
            inReader = new InputStreamReader(url.openStream());
            BufferedReader inEdges = new BufferedReader(inReader);
            while ((s = inEdges.readLine()) != null) edge.add(new Edge(s, inEdges.readLine(), inEdges.readLine(), inEdges.readLine()));
            inEdges.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String getMD5(final String text) {
        if (null == text) return null;
        final MessageDigest algorithm;
        try {
            algorithm = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        algorithm.reset();
        algorithm.update(text.getBytes());
        final byte[] digest = algorithm.digest();
        final StringBuffer hexString = new StringBuffer();
        for (byte b : digest) {
            String str = Integer.toHexString(0xFF & b);
            str = str.length() == 1 ? '0' + str : str;
            hexString.append(str);
        }
        return hexString.toString();
    }
public static void copyFile(File src, File dest, boolean preserveFileDate) throws IOException {
        if (src.exists() && src.isDirectory()) {
            throw new IOException("source file exists but is a directory");
        }
        if (dest.exists() && dest.isDirectory()) {
            dest = new File(dest, src.getName());
        }
        if (!dest.exists()) {
            dest.createNewFile();
        }
        FileChannel srcCH = null;
        FileChannel destCH = null;
        try {
            srcCH = new FileInputStream(src).getChannel();
            destCH = new FileOutputStream(dest).getChannel();
            destCH.transferFrom(srcCH, 0, srcCH.size());
        } finally {
            closeQuietly(srcCH);
            closeQuietly(destCH);
        }
        if (src.length() != dest.length()) {
            throw new IOException("Failed to copy full contents from '" + src + "' to '" + dest + "'");
        }
        if (preserveFileDate) {
            dest.setLastModified(src.lastModified());
        }
    }
public void login() throws Exception {
        String s_url = bean.getProtocol() + "://" + bean.getUrl() + ":" + bean.getPort() + "/login/login.cgi?" + "userType=1&" + "name=" + bean.getLogin() + "&" + "passwd=" + bean.getPassword() + "&" + "btn_submit=enter&" + "login_action=login&" + "path=&" + "restart=no&" + "systemfull=no";
        URL url = new URL(s_url);
        HttpURLConnection http = (HttpURLConnection) url.openConnection();
        HttpsURLConnectionImpl ssl = (HttpsURLConnectionImpl) http;
        ssl.setSSLSocketFactory(factory);
        ssl.setHostnameVerifier(new HostnameVerifier() {

            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
        http.setDoOutput(true);
        http.setDoInput(true);
        http.setAllowUserInteraction(true);
        int responseCode = http.getResponseCode();
        BufferedReader br = new BufferedReader(new InputStreamReader(http.getInputStream()));
        String tmp = br.readLine();
        StringWriter writer = new StringWriter();
        while (tmp != null) {
            writer.write(tmp + "\n");
            tmp = br.readLine();
        }
        writer.flush();
        writer.close();
        String s = writer.toString();
        String pattern = "<input type=\"hidden\" name=\"id\" value=\"";
        int i = s.indexOf(pattern);
        sessionId = s.substring(i + pattern.length(), s.indexOf("\"", i + pattern.length() + 1));
    }
public void put(File fileToPut) throws IOException {
        FTPClient ftp = new FTPClient();
        try {
            int reply;
            ftp.connect(this.endpointURL, Config.getFtpPort());
            log.debug("Ftp put reply: " + ftp.getReplyString());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp put server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            InputStream input = new FileInputStream(fileToPut);
            if (ftp.storeFile(fileToPut.getName(), input) != true) {
                ftp.logout();
                input.close();
                throw new IOException("FTP put exception");
            }
            input.close();
            ftp.logout();
        } catch (Exception e) {
            log.error("Ftp client exception: " + e.getMessage(), e);
            throw new IOException(e.getMessage());
        }
    }
public void get(File fileToGet) throws IOException {
        FTPClient ftp = new FTPClient();
        try {
            int reply = 0;
            ftp.connect(this.endpointURL, Config.getFtpPort());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp get server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            OutputStream output = new FileOutputStream(fileToGet.getName());
            if (ftp.retrieveFile(fileToGet.getName(), output) != true) {
                ftp.logout();
                output.close();
                throw new IOException("FTP get exception, maybe file not found");
            }
            ftp.logout();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
public void delete(String fileToDelete) throws IOException {
        FTPClient ftp = new FTPClient();
        try {
            int reply = 0;
            ftp.connect(this.endpointURL, Config.getFtpPort());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp delete server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.enterLocalPassiveMode();
            log.debug("Deleted: " + ftp.deleteFile(fileToDelete));
            ftp.logout();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
public boolean exists(String fileToCheck) throws IOException {
        FTPClient ftp = new FTPClient();
        boolean found = false;
        try {
            int reply = 0;
            ftp.connect(this.endpointURL, Config.getFtpPort());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp exists server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.enterLocalPassiveMode();
            if (ftp.listNames(fileToCheck) != null) {
                found = true;
            }
            ftp.logout();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
        return found;
    }
public static void copyfile(String src, String dst) throws IOException {
        dst = new File(dst).getAbsolutePath();
        new File(new File(dst).getParent()).mkdirs();
        FileChannel srcChannel = new FileInputStream(src).getChannel();
        FileChannel dstChannel = new FileOutputStream(dst).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
private static InputStream openNamedResource(String name) throws java.io.IOException {
        InputStream in = null;
        boolean result = false;
        boolean httpURL = true;
        URL propsURL = null;
        try {
            propsURL = new URL(name);
        } catch (MalformedURLException ex) {
            httpURL = false;
            propsURL = null;
        }
        if (propsURL == null) {
            propsURL = UserProperties.class.getResource(name);
        }
        if (propsURL != null) {
            URLConnection urlConn = propsURL.openConnection();
            if (httpURL) {
                String hdrVal = urlConn.getHeaderField(0);
                if (hdrVal != null) {
                    String code = HTTPUtilities.getResultCode(hdrVal);
                    if (code != null) {
                        if (!code.equals("200")) {
                            throw new java.io.IOException("status code = " + code);
                        }
                    }
                }
            }
            in = urlConn.getInputStream();
        }
        return in;
    }
public static final String enctrypt(String password) {
            MessageDigest md = null;
            byte[] byteHash = null;
            StringBuffer resultString = new StringBuffer();
            try {
                md = MessageDigest.getInstance("SHA1");
            } catch (NoSuchAlgorithmException e) {
                System.out.println("NoSuchAlgorithmException caught!");
                throw new RuntimeException("NoSuchAlgorithmException SHA1");
            }
            md.reset();
            md.update(password.getBytes());
            byteHash = md.digest();
            for (int i = 0; i < byteHash.length; i++) {
                resultString.append(Integer.toHexString(0xFF & byteHash[i]));
            }
            return (resultString.toString());
        }
protected String getManualDownloadURL() {
        if (_newestVersionString.indexOf("weekly") > 0) {
            return "http://www.cs.rice.edu/~javaplt/drjavarice/weekly/";
        }
        final String DRJAVA_FILES_PAGE = "http://sourceforge.net/project/showfiles.php?group_id=44253";
        final String LINK_PREFIX = "<a href=\"/project/showfiles.php?group_id=44253";
        final String LINK_SUFFIX = "\">";
        BufferedReader br = null;
        try {
            URL url = new URL(DRJAVA_FILES_PAGE);
            InputStream urls = url.openStream();
            InputStreamReader is = new InputStreamReader(urls);
            br = new BufferedReader(is);
            String line;
            int pos;
            while ((line = br.readLine()) != null) {
                if ((pos = line.indexOf(_newestVersionString)) >= 0) {
                    int prePos = line.indexOf(LINK_PREFIX);
                    if ((prePos >= 0) && (prePos < pos)) {
                        int suffixPos = line.indexOf(LINK_SUFFIX, prePos);
                        if ((suffixPos >= 0) && (suffixPos + LINK_SUFFIX.length() == pos)) {
                            String versionLink = edu.rice.cs.plt.text.TextUtil.xmlUnescape(line.substring(prePos + LINK_PREFIX.length(), suffixPos));
                            return DRJAVA_FILES_PAGE + versionLink;
                        }
                    }
                }
            }
            ;
        } catch (IOException e) {
            return DRJAVA_FILES_PAGE;
        } finally {
            try {
                if (br != null) br.close();
            } catch (IOException e) {
            }
        }
        return DRJAVA_FILES_PAGE;
    }
public void init(final javax.swing.text.Document doc) {
        this.doc = doc;
        String dtdLocation = null;
        String schemaLocation = null;
        SyntaxDocument mDoc = (SyntaxDocument) doc;
        Object mDtd = mDoc.getProperty(XPontusConstantsIF.PARSER_DATA_DTD_COMPLETION_INFO);
        Object mXsd = mDoc.getProperty(XPontusConstantsIF.PARSER_DATA_SCHEMA_COMPLETION_INFO);
        if (mDtd != null) {
            dtdLocation = mDtd.toString();
        }
        if (mXsd != null) {
            schemaLocation = mXsd.toString();
        }
        Object o = doc.getProperty("BUILTIN_COMPLETION");
        if (o != null) {
            if (o.equals("HTML")) {
                dtdLocation = getClass().getResource("xhtml.dtd").toExternalForm();
            }
        }
        try {
            if (dtdLocation != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Using dtd to build completion database");
                }
                setCompletionParser(new DTDCompletionParser());
                URL url = new java.net.URL(dtdLocation);
                Reader dtdReader = new InputStreamReader(url.openStream());
                updateAssistInfo(null, dtdLocation, dtdReader);
            } else if (schemaLocation != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Using schema  to build completion database");
                }
                setCompletionParser(new XSDCompletionParser());
                URL url = new java.net.URL(schemaLocation);
                Reader dtdReader = new InputStreamReader(url.openStream());
                updateAssistInfo(null, schemaLocation, dtdReader);
            }
        } catch (Exception err) {
            if (logger.isDebugEnabled()) {
                logger.debug(err.getMessage(), err);
            }
        }
    }
public static void copyFile(File in, File out) throws IOException {
        if (in.getCanonicalPath().equals(out.getCanonicalPath())) {
            return;
        }
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) {
                inChannel.close();
            }
            if (outChannel != null) {
                outChannel.close();
            }
        }
    }