semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public ManageUsers() {
        if (System.getProperty("user.home") != null) {
            dataFile = new File(System.getProperty("user.home") + File.separator + "MyRx" + File.separator + "MyRx.dat");
            File dataFileDir = new File(System.getProperty("user.home") + File.separator + "MyRx");
            dataFileDir.mkdirs();
        } else {
            dataFile = new File("MyRx.dat");
        }
        try {
            dataFile.createNewFile();
        } catch (IOException e1) {
            logger.error(e1);
            JOptionPane.showMessageDialog(Menu.getMainMenu(), e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        File oldDataFile = new File("MyRx.dat");
        if (oldDataFile.exists()) {
            FileChannel src = null, dst = null;
            try {
                src = new FileInputStream(oldDataFile.getAbsolutePath()).getChannel();
                dst = new FileOutputStream(dataFile.getAbsolutePath()).getChannel();
                dst.transferFrom(src, 0, src.size());
                if (!oldDataFile.delete()) {
                    oldDataFile.deleteOnExit();
                }
            } catch (FileNotFoundException e) {
                logger.error(e);
                JOptionPane.showMessageDialog(Menu.getMainMenu(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            } catch (IOException e) {
                logger.error(e);
                JOptionPane.showMessageDialog(Menu.getMainMenu(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            } finally {
                try {
                    src.close();
                    dst.close();
                } catch (IOException e) {
                    logger.error(e);
                }
            }
        }
    }
public String getScript(String script, String params) {
        params = params.replaceFirst("&", "?");
        StringBuffer document = new StringBuffer();
        try {
            URL url = new URL(script + params);
            URLConnection conn = url.openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                document.append(line + "\n");
            }
            reader.close();
        } catch (Exception e) {
            return e.toString();
        }
        return document.toString();
    }
public byte[] uniqueID(String name, String topic) {
        String key;
        byte[] id;
        synchronized (cache_) {
            key = name + "|" + topic;
            id = (byte[]) cache_.get(key);
            if (id == null) {
                MessageDigest md;
                try {
                    md = MessageDigest.getInstance("SHA");
                    md.update(name.getBytes());
                    md.update(topic.getBytes());
                    id = md.digest();
                    cache_.put(key, id);
                    if (debug_) {
                        System.out.println("Cached " + key + " [" + id[0] + "," + id[1] + ",...]");
                    }
                } catch (NoSuchAlgorithmException e) {
                    throw new Error("SHA not available!");
                }
            }
        }
        return id;
    }
public static void copyFile(File from, File to) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream(from);
            out = new FileOutputStream(to);
            byte[] bytes = new byte[1024 * 4];
            int len = 0;
            while ((len = in.read(bytes)) >= 0) out.write(bytes, 0, len);
        } finally {
            Streams.closeQuietly(in);
            Streams.closeQuietly(out);
        }
    }
public final String encrypt(final String plaintext, final String salt) {
        if (plaintext == null) {
            throw new NullPointerException();
        }
        if (salt == null) {
            throw new NullPointerException();
        }
        try {
            final MessageDigest md = MessageDigest.getInstance("SHA");
            md.update((plaintext + salt).getBytes("UTF-8"));
            return new BASE64Encoder().encode(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new EncryptionException(e);
        } catch (UnsupportedEncodingException e) {
            throw new EncryptionException(e);
        }
    }
static String getMD5Sum(String source) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(source.getBytes());
            byte[] md5sum = digest.digest();
            BigInteger bigInt = new BigInteger(1, md5sum);
            return bigInt.toString(16);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("MD5 algorithm seems to not be supported. This is a requirement!");
        }
    }
public static String digest(String algorithm, String text) {
        MessageDigest mDigest = null;
        try {
            mDigest = MessageDigest.getInstance(algorithm);
            mDigest.update(text.getBytes(ENCODING));
        } catch (Exception e) {
            e.printStackTrace();
            mDigest = null;
        }
        if (mDigest == null) return null;
        byte[] raw = mDigest.digest();
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(raw);
    }
public static void storePolicy(DBBroker broker, XmldbURI docPath) throws EXistException, IOException {
        XmldbURI docName = docPath.lastSegment();
        URL url = XACMLUtil.class.getResource(docPath.toString());
        if (url == null) return;
        String content = toString(url.openStream());
        if (content == null) return;
        Collection collection = getPolicyCollection(broker);
        if (collection == null) return;
        TransactionManager transact = broker.getBrokerPool().getTransactionManager();
        Txn txn = transact.beginTransaction();
        try {
            IndexInfo info = collection.validateXMLResource(txn, broker, docName, content);
            collection.store(txn, broker, info, content, false);
            transact.commit(txn);
        } catch (Exception e) {
            transact.abort(txn);
            if (e instanceof EXistException) throw (EXistException) e;
            throw new EXistException("Error storing policy '" + docPath + "'", e);
        }
    }
private static void init() {
        try {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            Enumeration<URL> enumeration = cl.getResources("extension-services.properties");
            do {
                if (!enumeration.hasMoreElements()) break;
                URL url = (URL) enumeration.nextElement();
                System.out.println(" - " + url);
                try {
                    props = new Properties();
                    props.load(url.openStream());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } while (true);
        } catch (IOException e) {
        }
    }
private MimeTypesProvider() {
        File mimeTypesFile = new File(XPontusConstantsIF.XPONTUS_HOME_DIR, "mimes.properties");
        try {
            if (!mimeTypesFile.exists()) {
                OutputStream os = null;
                InputStream is = getClass().getResourceAsStream("/net/sf/xpontus/configuration/mimetypes.properties");
                os = FileUtils.openOutputStream(mimeTypesFile);
                IOUtils.copy(is, os);
                IOUtils.closeQuietly(is);
                IOUtils.closeQuietly(os);
            }
            provider = new XPontusMimetypesFileTypeMap(mimeTypesFile.getAbsolutePath());
            MimetypesFileTypeMap.setDefaultFileTypeMap(provider);
        } catch (Exception err) {
            err.printStackTrace();
        }
    }
private boolean streamDownload(URL url, File file) {
        try {
            InputStream in = url.openConnection().getInputStream();
            BufferedInputStream bis = new BufferedInputStream(in);
            OutputStream out = new FileOutputStream(file);
            BufferedOutputStream bos = new BufferedOutputStream(out);
            int chunkSize = 63 * 1024;
            byte[] ba = new byte[chunkSize];
            while (true) {
                int bytesRead = readBlocking(bis, ba, 0, chunkSize);
                if (bytesRead > 0) {
                    if (bos != null) bos.write(ba, 0, bytesRead);
                } else {
                    bos.close();
                    break;
                }
            }
        } catch (IOException e) {
            System.out.println("Error writing file " + file);
            return false;
        }
        System.out.println("OK writing file " + file);
        return true;
    }
public static void hash(String... plainTexts) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            for (String plainText : plainTexts) md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0) i += 256;
                if (i < 16) buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            String str = buf.toString();
            System.out.println("result: " + buf.toString());
            System.out.println("result: " + buf.toString().substring(8, 24));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
public static String MD5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        byte[] md5hash;
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
public static void main(String args[]) throws Exception {
        FileInputStream fin = new FileInputStream("D:/work/test.txt");
        FileOutputStream fout = new FileOutputStream("D:/work/output.txt");
        FileChannel inChannel = fin.getChannel();
        FileChannel outChannel = fout.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (true) {
            int ret = inChannel.read(buffer);
            if (ret == -1) break;
            buffer.flip();
            outChannel.write(buffer);
            buffer.clear();
        }
    }
private void loadBinaryStream(String streamName, InputStream streamToLoad, long sz, HttpServletRequest req, HttpServletResponse resp) throws IOException {
            resp.setContentType(getContentType(req, streamName));
            resp.setHeader("Content-Disposition", "inline;filename=" + streamName);
            resp.setContentLength((int) sz);
            OutputStream out = resp.getOutputStream();
            BufferedOutputStream bos = new BufferedOutputStream(out, 2048);
            try {
                IOUtils.copy(streamToLoad, bos);
            } finally {
                IOUtils.closeQuietly(streamToLoad);
                IOUtils.closeQuietly(bos);
            }
            getCargo().put(GWT_ENTRY_POINT_PAGE_PARAM, null);
        }
public static void copyFile(File source, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
public static String Sha1(String s) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] hash = new byte[40];
            md.update(s.getBytes("iso-8859-1"), 0, s.length());
            hash = md.digest();
            return toHex(hash);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
public void applyTo(File source, File target) throws IOException {
            boolean failed = true;
            FileInputStream fin = new FileInputStream(source);
            try {
                FileChannel in = fin.getChannel();
                FileOutputStream fos = new FileOutputStream(target);
                try {
                    FileChannel out = fos.getChannel();
                    long pos = 0L;
                    for (Replacement replacement : replacements) {
                        in.transferTo(pos, replacement.pos - pos, out);
                        if (replacement.val != null) out.write(ByteBuffer.wrap(replacement.val));
                        pos = replacement.pos + replacement.len;
                    }
                    in.transferTo(pos, source.length() - pos, out);
                    failed = false;
                } finally {
                    fos.close();
                    if (failed == true) target.delete();
                }
            } finally {
                fin.close();
            }
        }
private String getJsonString(String url) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()), 8192);
        String line = reader.readLine();
        String jsonString = "";
        while (line != null) {
            jsonString += line;
            line = reader.readLine();
        }
        jsonString = jsonString.substring(jsonString.indexOf(":") + 1, jsonString.length() - 1);
        return jsonString;
    }
private InputStream getManifestAsResource() {
        ClassLoader cl = getClass().getClassLoader();
        try {
            Enumeration manifests = cl != null ? cl.getResources(Constants.OSGI_BUNDLE_MANIFEST) : ClassLoader.getSystemResources(Constants.OSGI_BUNDLE_MANIFEST);
            while (manifests.hasMoreElements()) {
                URL url = (URL) manifests.nextElement();
                try {
                    Headers headers = Headers.parseManifest(url.openStream());
                    if ("true".equals(headers.get(Constants.ECLIPSE_SYSTEMBUNDLE))) return url.openStream();
                } catch (BundleException e) {
                }
            }
        } catch (IOException e) {
        }
        return null;
    }
public void run() {
        m_stats.setRunning();
        URL url = m_stats.url;
        if (url != null) {
            try {
                URLConnection connection = url.openConnection();
                if (connection instanceof HttpURLConnection) {
                    HttpURLConnection httpConnection = (HttpURLConnection) connection;
                    handleHTTPConnection(httpConnection, m_stats);
                } else {
                    System.out.println("Unknown URL Connection Type " + url);
                }
            } catch (java.io.IOException ioe) {
                m_stats.setStatus(m_stats.IOError);
                m_stats.setErrorString("Error making or reading from connection" + ioe.toString());
            }
        }
        m_stats.setDone();
        m_manager.threadFinished(this);
    }
private InputStream getStreamFromUrl(URL url, String notFoundMessage) throws ApolloAdapterException {
        InputStream stream = null;
        if (url == null) {
            String message = "Couldn't find url for " + filename;
            logger.error(message);
            throw new ApolloAdapterException(message);
        }
        if (url != null) {
            try {
                stream = url.openStream();
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
                stream = null;
                throw new ApolloAdapterException(e);
            }
        }
        return stream;
    }
public File createTemporaryFile() throws IOException {
        URL url = clazz.getResource(resource);
        if (url == null) {
            throw new IOException("No resource available from '" + clazz.getName() + "' for '" + resource + "'");
        }
        String extension = getExtension(resource);
        String prefix = "resource-temporary-file-creator";
        File file = File.createTempFile(prefix, extension);
        InputStream input = url.openConnection().getInputStream();
        FileOutputStream output = new FileOutputStream(file);
        com.volantis.synergetics.io.IOUtils.copyAndClose(input, output);
        return file;
    }
public static List<Item> doService(List<String> itemIds, Boolean archive) throws UnsupportedEncodingException, IOException {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        ToggleArchiveRequest request = new ToggleArchiveRequest();
        String sessionId = (String) RuntimeAccess.getInstance().getSession().getAttribute("SESSION_ID");
        request.setItemIds(itemIds);
        request.setArchive(archive);
        request.setSessionId(sessionId);
        XStream writer = new XStream();
        writer.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        writer.alias("ToggleArchiveRequest", ToggleArchiveRequest.class);
        XStream reader = new XStream();
        reader.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        reader.alias("ToggleArchiveResponse", ToggleArchiveResponse.class);
        String strRequest = URLEncoder.encode(reader.toXML(request), "UTF-8");
        HttpPost httppost = new HttpPost(MewitProperties.getMewitUrl() + "/resources/toggleArchive?REQUEST=" + strRequest);
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = URLDecoder.decode(EntityUtils.toString(entity), "UTF-8");
            ToggleArchiveResponse oResponse = (ToggleArchiveResponse) reader.fromXML(result);
            return oResponse.getItems();
        }
        return null;
    }
private File getTempFile(DigitalObject object, String pid) throws Exception {
        File directory = new File(tmpDir, object.getId());
        File target = new File(directory, pid);
        if (!target.exists()) {
            target.getParentFile().mkdirs();
            target.createNewFile();
        }
        Payload payload = object.getPayload(pid);
        InputStream in = payload.open();
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(target);
            IOUtils.copyLarge(in, out);
        } catch (Exception ex) {
            close(out);
            target.delete();
            payload.close();
            throw ex;
        }
        close(out);
        payload.close();
        return target;
    }
public boolean connectServer(String server, String user, String password) {
        boolean result = true;
        try {
            if (user.equals("")) {
                user = "anonymous";
                password = "anonymous";
            }
            this.server = server;
            this.user = user;
            this.password = password;
            ftpClient = new FTPClient();
            ftpClient.setControlEncoding(encode);
            ftpClient.connect(server);
            ftpClient.setSoTimeout(1000 * 30);
            ftpClient.setDefaultTimeout(1000 * 30);
            ftpClient.setConnectTimeout(1000 * 30);
            ftpClient.enterLocalPassiveMode();
            ftpClient.login(user, password);
            if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                ftpClient.disconnect();
                return false;
            }
            queFilePath = "data\\" + this.server + ".que";
            bufFilePath = "data\\" + this.server + ".buf";
            startGetList();
        } catch (java.net.SocketTimeoutException e1) {
            errMsg = ftpClient.getReplyString();
            errCode = ftpClient.getReplyCode();
            result = false;
            setArrToFile(dirQueue, queFilePath);
            setArrToFile(fileList, bufFilePath);
            cn.imgdpu.util.CatException.getMethod().catException(e1, "连接超时");
        } catch (Exception e) {
            errMsg = ftpClient.getReplyString();
            errCode = ftpClient.getReplyCode();
            result = false;
            setArrToFile(dirQueue, queFilePath);
            setArrToFile(fileList, bufFilePath);
            cn.imgdpu.util.CatException.getMethod().catException(e, "未知异常");
        } finally {
            if (ftpClient.isConnected()) {
                try {
                    ftpClient.disconnect();
                } catch (IOException ioe) {
                    cn.imgdpu.util.CatException.getMethod().catException(ioe, "IO异常");
                }
            }
        }
        return result;
    }
public void execute() {
        check();
        FTPClient ftp = new FTPClient();
        try {
            ftp.connect(host, port);
        } catch (IOException ex) {
            throw new BuildException("FTP connexion failed : IOException caught (" + ex.getMessage() + ")");
        }
        if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
            throw new BuildException("FTP connexion failed : " + ftp.getReplyString());
        }
        try {
            try {
                if (!ftp.login(userid, password)) {
                    throw new BuildException("Identification failed");
                }
            } catch (IOException ex) {
                throw new BuildException(ex);
            }
            if (binary) {
                try {
                    ftp.setFileType(FTP.IMAGE_FILE_TYPE);
                } catch (IOException ex) {
                    throw new BuildException(ex);
                }
                if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                    throw new BuildException("Transfer type not supported : " + ftp.getReplyString());
                }
            }
            try {
                ftp.changeWorkingDirectory(remotedir);
            } catch (IOException ex) {
                throw new BuildException(ex);
            }
            if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                throw new BuildException("Unacessible remote directory : " + ftp.getReplyString());
            }
            String localFullFileName = Files.normalizeDirectoryName(localdir) + remotefile;
            String remoteFullFileName = (remotedir.endsWith(serverpathseparator) ? remotedir : remotedir + serverpathseparator) + remotefile;
            BufferedOutputStream outstream = null;
            try {
                outstream = new BufferedOutputStream(new FileOutputStream(localFullFileName));
                ftp.retrieveFile(remoteFullFileName, outstream);
            } catch (IOException ex) {
                throw new BuildException(ex);
            }
            if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                throw new BuildException("File retrieval of '" + localFullFileName + "' has failed (" + ftp.getReplyString() + ")");
            }
        } finally {
            try {
                ftp.disconnect();
            } catch (IOException ex) {
                System.err.println("Disconnexion from " + host + ":" + port + " failed");
            }
        }
    }