semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected void saveSelectedFiles() {
        if (dataList.getSelectedRowCount() == 0) {
            return;
        }
        if (dataList.getSelectedRowCount() == 1) {
            Object obj = model.getItemAtRow(sorter.convertRowIndexToModel(dataList.getSelectedRow()));
            AttachFile entry = (AttachFile) obj;
            JFileChooser fc = new JFileChooser();
            fc.setSelectedFile(new File(fc.getCurrentDirectory(), entry.getCurrentPath().getName()));
            if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                File current = entry.getCurrentPath();
                File dest = fc.getSelectedFile();
                try {
                    FileInputStream in = new FileInputStream(current);
                    FileOutputStream out = new FileOutputStream(dest);
                    byte[] readBuf = new byte[1024 * 512];
                    int readLength;
                    while ((readLength = in.read(readBuf)) != -1) {
                        out.write(readBuf, 0, readLength);
                    }
                    in.close();
                    out.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return;
        } else {
            JFileChooser fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                for (Integer idx : dataList.getSelectedRows()) {
                    Object obj = model.getItemAtRow(sorter.convertRowIndexToModel(idx));
                    AttachFile entry = (AttachFile) obj;
                    File current = entry.getCurrentPath();
                    File dest = new File(fc.getSelectedFile(), entry.getName());
                    try {
                        FileInputStream in = new FileInputStream(current);
                        FileOutputStream out = new FileOutputStream(dest);
                        byte[] readBuf = new byte[1024 * 512];
                        int readLength;
                        while ((readLength = in.read(readBuf)) != -1) {
                            out.write(readBuf, 0, readLength);
                        }
                        in.close();
                        out.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return;
        }
    }
public void copyTo(File folder) {
            if (!isNewFile()) {
                return;
            }
            if (!folder.exists()) {
                folder.mkdir();
            }
            File dest = new File(folder, name);
            try {
                FileInputStream in = new FileInputStream(currentPath);
                FileOutputStream out = new FileOutputStream(dest);
                byte[] readBuf = new byte[1024 * 512];
                int readLength;
                long totalCopiedSize = 0;
                boolean canceled = false;
                while ((readLength = in.read(readBuf)) != -1) {
                    out.write(readBuf, 0, readLength);
                }
                in.close();
                out.close();
                if (canceled) {
                    dest.delete();
                } else {
                    currentPath = dest;
                    newFile = false;
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
private static String[] loadDB(String name) throws IOException {
        URL url = SpecialConstants.class.getResource(name);
        if (url == null) throw new FileNotFoundException("file " + name + " not found");
        InputStream is = url.openStream();
        try {
            InputStreamReader isr = new InputStreamReader(is, "utf8");
            BufferedReader br = new BufferedReader(isr);
            ArrayList<String> entries = new ArrayList<String>();
            while (true) {
                String line = br.readLine();
                if (line == null) break;
                line = line.trim();
                if (line.length() > 0 && line.charAt(0) != '#') {
                    entries.add(line);
                }
            }
            String[] r = new String[entries.size()];
            entries.toArray(r);
            return r;
        } finally {
            is.close();
        }
    }
public static void copyFile(String sourceName, String destName) throws IOException {
        FileChannel sourceChannel = null;
        FileChannel destChannel = null;
        try {
            sourceChannel = new FileInputStream(sourceName).getChannel();
            destChannel = new FileOutputStream(destName).getChannel();
            destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        } catch (IOException exception) {
            throw exception;
        } finally {
            if (sourceChannel != null) {
                try {
                    sourceChannel.close();
                } catch (IOException ex) {
                }
            }
            if (destChannel != null) {
                try {
                    destChannel.close();
                } catch (IOException ex) {
                }
            }
        }
    }
private void checkUrl(URL url) throws IOException {
        File urlFile = new File(url.getFile());
        assertEquals(file.getCanonicalPath(), urlFile.getCanonicalPath());
        System.out.println("Using url " + url);
        InputStream openStream = url.openStream();
        assertNotNull(openStream);
    }
public boolean PrintPage(String page, String url_addr, String charset) {
        File parent_path = new File(new File(page).getParent());
        if (!parent_path.exists()) {
            parent_path.mkdirs();
        }
        String r_line = null;
        BufferedReader bReader = null;
        FileOutputStream out = null;
        OutputStreamWriter writer = null;
        PrintWriter fileOut = null;
        File file = null;
        try {
            InputStream ins = new URL(url_addr).openStream();
            file = new File(page);
            if (!file.exists()) {
                file.createNewFile();
            }
            bReader = new BufferedReader(new InputStreamReader(ins, charset));
            out = new FileOutputStream(page);
            writer = new OutputStreamWriter(out, charset);
            fileOut = new PrintWriter(writer);
            while ((r_line = bReader.readLine()) != null) {
                r_line = r_line.trim();
                int str_len = r_line.length();
                if (str_len > 0) {
                    fileOut.println(r_line);
                    fileOut.flush();
                }
            }
            ins.close();
            ins = null;
            fileOut.close();
            writer.close();
            out.close();
            bReader.close();
            fileOut = null;
            writer = null;
            out = null;
            bReader = null;
            parent_path = null;
            file = null;
            r_line = null;
            return true;
        } catch (IOException ioe) {
            log.error(ioe.getMessage());
            ioe.printStackTrace();
            return false;
        } catch (Exception es) {
            es.printStackTrace();
            log.error("static----------" + es.getMessage());
            return false;
        } finally {
            try {
                if (fileOut != null) {
                    fileOut.close();
                    fileOut = null;
                }
                if (writer != null) {
                    writer.close();
                    writer = null;
                }
                if (out != null) {
                    out.close();
                    out = null;
                }
                if (bReader != null) {
                    bReader.close();
                    bReader = null;
                }
            } catch (IOException ioe) {
                log.error(ioe.getMessage());
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }
    }
public String hash(String plaintext, String salt, int iterations) throws EncryptionException {
        byte[] bytes = null;
        try {
            MessageDigest digest = MessageDigest.getInstance(hashAlgorithm);
            digest.reset();
            digest.update(ESAPI.securityConfiguration().getMasterSalt());
            digest.update(salt.getBytes(encoding));
            digest.update(plaintext.getBytes(encoding));
            bytes = digest.digest();
            for (int i = 0; i < iterations; i++) {
                digest.reset();
                bytes = digest.digest(bytes);
            }
            String encoded = ESAPI.encoder().encodeForBase64(bytes, false);
            return encoded;
        } catch (NoSuchAlgorithmException e) {
            throw new EncryptionException("Internal error", "Can't find hash algorithm " + hashAlgorithm, e);
        } catch (UnsupportedEncodingException ex) {
            throw new EncryptionException("Internal error", "Can't find encoding for " + encoding, ex);
        }
    }
public void SendFile(File testfile) {
        try {
            SocketChannel sock = SocketChannel.open(new InetSocketAddress("127.0.0.1", 1234));
            sock.configureBlocking(true);
            while (!sock.finishConnect()) {
                System.out.println("NOT connected!");
            }
            System.out.println("CONNECTED!");
            FileInputStream fis = new FileInputStream(testfile);
            FileChannel fic = fis.getChannel();
            long len = fic.size();
            Buffer.clear();
            Buffer.putLong(len);
            Buffer.flip();
            sock.write(Buffer);
            long cnt = 0;
            while (cnt < len) {
                Buffer.clear();
                int add = fic.read(Buffer);
                cnt += add;
                Buffer.flip();
                while (Buffer.hasRemaining()) {
                    sock.write(Buffer);
                }
            }
            fic.close();
            File tmpfile = getTmp().createNewFile("tmp", "tmp");
            FileOutputStream fos = new FileOutputStream(tmpfile);
            FileChannel foc = fos.getChannel();
            int mlen = -1;
            do {
                Buffer.clear();
                mlen = sock.read(Buffer);
                Buffer.flip();
                if (mlen > 0) {
                    foc.write(Buffer);
                }
            } while (mlen > 0);
            foc.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public String getResourceAsString(String name) throws IOException {
        String content = null;
        InputStream stream = aClass.getResourceAsStream(name);
        if (stream != null) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            IOUtils.copyAndClose(stream, buffer);
            content = buffer.toString();
        } else {
            Assert.fail("Resource not available: " + name);
        }
        return content;
    }
private String _doPost(final String urlStr, final Map<String, String> params) {
        String paramsStr = "";
        for (String key : params.keySet()) {
            try {
                paramsStr += URLEncoder.encode(key, ENCODING) + "=" + URLEncoder.encode(params.get(key), ENCODING) + "&";
            } catch (UnsupportedEncodingException e) {
                s_logger.debug("UnsupportedEncodingException caught. Trying to encode: " + key + " and " + params.get(key));
                return null;
            }
        }
        if (paramsStr.length() == 0) {
            s_logger.debug("POST will not complete, no parameters specified.");
            return null;
        }
        s_logger.debug("POST to server will be done with the following parameters: " + paramsStr);
        HttpURLConnection connection = null;
        String responseStr = null;
        try {
            connection = (HttpURLConnection) (new URL(urlStr)).openConnection();
            connection.setRequestMethod(REQUEST_METHOD);
            connection.setDoOutput(true);
            DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
            dos.write(paramsStr.getBytes());
            dos.flush();
            dos.close();
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
            rd.close();
            responseStr = response.toString();
        } catch (ProtocolException e) {
            s_logger.debug("ProtocolException caught. Unable to execute POST.");
        } catch (MalformedURLException e) {
            s_logger.debug("MalformedURLException caught. Unexpected. Url is: " + urlStr);
        } catch (IOException e) {
            s_logger.debug("IOException caught. Unable to execute POST.");
        }
        return responseStr;
    }
public MsgRecvInfo[] recvMsg(MsgRecvReq msgRecvReq) throws SQLException {
        String updateSQL = " update dyhikemomessages set receive_id = ?, receive_Time = ?  where mo_to =? and receive_id =0  limit 20";
        String selectSQL = " select MOMSG_ID,mo_from,mo_to,create_time,mo_content from dyhikemomessages where receive_id =?  ";
        String insertSQL = " insert into t_receive_history select * from dyhikemomessages  where receive_id =?  ";
        String deleteSQL = " delete from dyhikemomessages where receive_id =? ";
        Logger logger = Logger.getLogger(this.getClass());
        ArrayList msgInfoList = new ArrayList();
        String mo_to = msgRecvReq.getAuthInfo().getUserName();
        MsgRecvInfo[] msgInfoArray = new ototype.MsgRecvInfo[0];
        String receiveTime = Const.DF.format(new Date());
        logger.debug("recvMsgNew1");
        Connection conn = null;
        try {
            int receiveID = this.getSegquence("receiveID");
            conn = this.getJdbcTemplate().getDataSource().getConnection();
            conn.setAutoCommit(false);
            PreparedStatement pstmt = conn.prepareStatement(updateSQL);
            pstmt.setInt(1, receiveID);
            pstmt.setString(2, receiveTime);
            pstmt.setString(3, mo_to);
            int recordCount = pstmt.executeUpdate();
            logger.info(recordCount + " record(s) got");
            if (recordCount > 0) {
                pstmt = conn.prepareStatement(selectSQL);
                pstmt.setInt(1, receiveID);
                ResultSet rs = pstmt.executeQuery();
                while (rs.next()) {
                    MsgRecvInfo msg = new MsgRecvInfo();
                    msg.setDestMobile(rs.getString("mo_to"));
                    msg.setRecvAddi(rs.getString("mo_to"));
                    msg.setSendAddi(rs.getString("MO_FROM"));
                    msg.setContent(rs.getString("mo_content"));
                    msg.setRecvDate(rs.getString("create_time"));
                    msgInfoList.add(msg);
                }
                msgInfoArray = (MsgRecvInfo[]) msgInfoList.toArray(new MsgRecvInfo[msgInfoList.size()]);
                pstmt = conn.prepareStatement(insertSQL);
                pstmt.setInt(1, receiveID);
                pstmt.execute();
                pstmt = conn.prepareStatement(deleteSQL);
                pstmt.setInt(1, receiveID);
                pstmt.execute();
                conn.commit();
            }
            logger.debug("recvMsgNew2");
            return msgInfoArray;
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            if (conn != null) {
                conn.setAutoCommit(true);
                conn.close();
            }
        }
    }
public XMLPieChartDemo(final String title) {
        super(title);
        PieDataset dataset = null;
        final URL url = getClass().getResource("/org/jfree/chart/demo/piedata.xml");
        try {
            final InputStream in = url.openStream();
            dataset = DatasetReader.readPieDatasetFromXML(in);
        } catch (IOException ioe) {
            System.out.println(ioe.getMessage());
        }
        final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", dataset, true, true, false);
        chart.setBackgroundPaint(Color.yellow);
        final PiePlot plot = (PiePlot) chart.getPlot();
        plot.setNoDataMessage("No data available");
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);
    }
private boolean performModuleInstallation(Model m) {
        String seldir = directoryHandler.getSelectedDirectory();
        if (seldir == null) {
            MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
            box.setText("Cannot install");
            box.setMessage("A target directory must be selected.");
            box.open();
            return false;
        }
        String sjar = pathText.getText();
        File fjar = new File(sjar);
        if (!fjar.exists()) {
            MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
            box.setText("Cannot install");
            box.setMessage("A non-existing jar file has been selected.");
            box.open();
            return false;
        }
        int count = 0;
        try {
            URLClassLoader loader = new URLClassLoader(new URL[] { fjar.toURI().toURL() });
            JarInputStream jis = new JarInputStream(new FileInputStream(fjar));
            JarEntry entry = jis.getNextJarEntry();
            while (entry != null) {
                String name = entry.getName();
                if (name.endsWith(".class")) {
                    name = name.substring(0, name.length() - 6);
                    name = name.replace('/', '.');
                    Class<?> cls = loader.loadClass(name);
                    if (IAlgorithm.class.isAssignableFrom(cls) && !cls.isInterface() && (cls.getModifiers() & Modifier.ABSTRACT) == 0) {
                        if (!testAlgorithm(cls, m)) return false;
                        count++;
                    }
                }
                entry = jis.getNextJarEntry();
            }
        } catch (Exception e1) {
            Application.logexcept("Could not load classes from jar file.", e1);
            return false;
        }
        if (count == 0) {
            MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
            box.setText("Cannot install");
            box.setMessage("There don't seem to be any algorithms in the specified module.");
            box.open();
            return false;
        }
        try {
            FileChannel ic = new FileInputStream(sjar).getChannel();
            FileChannel oc = new FileOutputStream(seldir + File.separator + fjar.getName()).getChannel();
            ic.transferTo(0, ic.size(), oc);
            ic.close();
            oc.close();
        } catch (Exception e) {
            Application.logexcept("Could not install module", e);
            return false;
        }
        result = new Object();
        return true;
    }
public void overwriteFileTest() throws Exception {
        File filefrom = new File("/tmp/from.txt");
        File fileto = new File("/tmp/to.txt");
        InputStream from = null;
        OutputStream to = null;
        try {
            from = new FileInputStream(filefrom);
            to = new FileOutputStream(fileto);
            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) {
                from.close();
            }
            if (to != null) {
                to.close();
            }
        }
    }
public void overwriteTest() throws Exception {
        SRBAccount srbAccount = new SRBAccount("srb1.ngs.rl.ac.uk", 5544, this.cred);
        srbAccount.setDefaultStorageResource("ral-ngs1");
        SRBFileSystem client = new SRBFileSystem(srbAccount);
        client.setFirewallPorts(64000, 65000);
        String home = client.getHomeDirectory();
        System.out.println("home: " + home);
        SRBFile file = new SRBFile(client, home + "/test.txt");
        assertTrue(file.exists());
        File filefrom = new File("/tmp/from.txt");
        assertTrue(filefrom.exists());
        SRBFileOutputStream to = null;
        InputStream from = null;
        try {
            to = new SRBFileOutputStream((SRBFile) file);
            from = new FileInputStream(filefrom);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) {
                to.write(buffer, 0, bytes_read);
            }
            to.flush();
        } finally {
            try {
                if (to != null) {
                    to.close();
                }
            } catch (Exception ex) {
            }
            try {
                if (from != null) {
                    from.close();
                }
            } catch (Exception ex) {
            }
        }
    }
public static String hash(String text) throws Exception {
        StringBuffer hexString;
        MessageDigest mdAlgorithm = MessageDigest.getInstance("MD5");
        mdAlgorithm.update(text.getBytes());
        byte[] digest = mdAlgorithm.digest();
        hexString = new StringBuffer();
        for (int i = 0; i < digest.length; i++) {
            text = Integer.toHexString(0xFF & digest[i]);
            if (text.length() < 2) {
                text = "0" + text;
            }
            hexString.append(text);
        }
        return hexString.toString();
    }
public static String MD5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        byte[] md5hash = new byte[32];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
@Override
    public void discoverPlugIns() throws PlugInManagerException {
        LOG.info("Discovering plug-ins defined in JAR manifests...");
        ClassLoader classLoader = this.getClass().getClassLoader();
        Enumeration<URL> manifests = null;
        try {
            manifests = classLoader.getResources(MANIFEST_RESOURCE);
            if (manifests == null || !manifests.hasMoreElements()) {
                LOG.info("No provider manifests found");
                return;
            }
        } catch (IOException ex) {
            LOG.error("Discovery failed", ex);
            return;
        }
        while (manifests.hasMoreElements()) {
            URL url = manifests.nextElement();
            try {
                Manifest manifest = new Manifest(url.openStream());
                LOG.debug("Validating manifest with URL of " + url);
                if (validatePlugInInfo(manifest)) {
                    P plugIn = instantiatePlugIn(manifest);
                    registerPlugIn(plugIn);
                }
            } catch (IOException e) {
                LOG.error("Failed to load manifest with url " + url, e);
            } catch (InvalidPlugInException e) {
                LOG.error("Provider with url " + url + " is not valid", e);
            } catch (PlugInInstantiationException e) {
                LOG.error("Provider with url " + url + " could not be instantiated", e);
            } catch (Exception e) {
                LOG.error("Provider with url " + url + " could not be initialized", e);
            }
        }
        LOG.info("Found and successfully validated " + getPlugIns().size() + " plug-ins");
    }