semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
        if (destFile.exists() && destFile.isDirectory()) {
            throw new IOException("Destination '" + destFile + "' exists but is a directory");
        }
        FileChannel input = new FileInputStream(srcFile).getChannel();
        try {
            FileChannel output = new FileOutputStream(destFile).getChannel();
            try {
                output.transferFrom(input, 0, input.size());
            } finally {
                IOUtils.closeQuietly(output);
            }
        } finally {
            IOUtils.closeQuietly(input);
        }
        if (srcFile.length() != destFile.length()) {
            throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
        }
        if (preserveFileDate) {
            destFile.setLastModified(srcFile.lastModified());
        }
    }
private String save(UploadedFile imageFile) {
        try {
            File saveFld = new File(imageFolder + File.separator + userDisplay.getUser().getUsername());
            if (!saveFld.exists()) {
                if (!saveFld.mkdir()) {
                    logger.info("Unable to create folder: " + saveFld.getAbsolutePath());
                    return null;
                }
            }
            File tmp = File.createTempFile("img", "img");
            IOUtils.copy(imageFile.getInputstream(), new FileOutputStream(tmp));
            File thumbnailImage = new File(saveFld + File.separator + UUID.randomUUID().toString() + ".png");
            File fullResolution = new File(saveFld + File.separator + UUID.randomUUID().toString() + ".png");
            BufferedImage image = ImageIO.read(tmp);
            Image thumbnailIm = image.getScaledInstance(310, 210, Image.SCALE_SMOOTH);
            BufferedImage thumbnailBi = new BufferedImage(thumbnailIm.getWidth(null), thumbnailIm.getHeight(null), BufferedImage.TYPE_INT_RGB);
            Graphics bg = thumbnailBi.getGraphics();
            bg.drawImage(thumbnailIm, 0, 0, null);
            bg.dispose();
            ImageIO.write(thumbnailBi, "png", thumbnailImage);
            ImageIO.write(image, "png", fullResolution);
            if (!tmp.delete()) {
                logger.info("Unable to delete: " + tmp.getAbsolutePath());
            }
            String imageId = UUID.randomUUID().toString();
            imageBean.addImage(imageId, new ImageRecord(imageFile.getFileName(), fullResolution.getAbsolutePath(), thumbnailImage.getAbsolutePath(), userDisplay.getUser().getUsername()));
            return imageId;
        } catch (Throwable t) {
            logger.log(Level.SEVERE, "Unable to save the image.", t);
            return null;
        }
    }
public List load(String sourceType, Object source, String param) throws Exception {
        if (log.isTraceEnabled()) {
            log.trace("load " + source);
        }
        String location = null;
        String type = null;
        Object inputsource = null;
        if (source instanceof DynamicMBean) {
            sourceType = "MbeansDescriptorsDynamicMBeanSource";
            inputsource = source;
        } else if (source instanceof URL) {
            URL url = (URL) source;
            location = url.toString();
            type = param;
            inputsource = url.openStream();
            if (sourceType == null) {
                sourceType = sourceTypeFromExt(location);
            }
        } else if (source instanceof File) {
            location = ((File) source).getAbsolutePath();
            inputsource = new FileInputStream((File) source);
            type = param;
            if (sourceType == null) {
                sourceType = sourceTypeFromExt(location);
            }
        } else if (source instanceof InputStream) {
            type = param;
            inputsource = source;
        } else if (source instanceof Class) {
            location = ((Class) source).getName();
            type = param;
            inputsource = source;
            if (sourceType == null) {
                sourceType = "MbeansDescriptorsIntrospectionSource";
            }
        }
        if (sourceType == null) {
            sourceType = "MbeansDescriptorsDigesterSource";
        }
        ModelerSource ds = getModelerSource(sourceType);
        List mbeans = ds.loadDescriptors(this, location, type, inputsource);
        return mbeans;
    }
public static void main(String[] args) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        String text = "YUMyfj";
        md.update(text.getBytes(), 0, text.length());
        System.out.println(new BigInteger(1, md.digest()).toString(16).toString());
    }
public void run() {
        try {
            String s = (new StringBuilder()).append("fName=").append(URLEncoder.encode("???", "UTF-8")).append("&lName=").append(URLEncoder.encode("???", "UTF-8")).toString();
            URL url = new URL("http://snoop.minecraft.net/");
            HttpURLConnection httpurlconnection = (HttpURLConnection) url.openConnection();
            httpurlconnection.setRequestMethod("POST");
            httpurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            httpurlconnection.setRequestProperty("Content-Length", (new StringBuilder()).append("").append(Integer.toString(s.getBytes().length)).toString());
            httpurlconnection.setRequestProperty("Content-Language", "en-US");
            httpurlconnection.setUseCaches(false);
            httpurlconnection.setDoInput(true);
            httpurlconnection.setDoOutput(true);
            DataOutputStream dataoutputstream = new DataOutputStream(httpurlconnection.getOutputStream());
            dataoutputstream.writeBytes(s);
            dataoutputstream.flush();
            dataoutputstream.close();
            java.io.InputStream inputstream = httpurlconnection.getInputStream();
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
            StringBuffer stringbuffer = new StringBuffer();
            String s1;
            while ((s1 = bufferedreader.readLine()) != null) {
                stringbuffer.append(s1);
                stringbuffer.append('\r');
            }
            bufferedreader.close();
        } catch (Exception exception) {
        }
    }
private void makeConn(String filename1, String filename2) {
        String basename = "http://www.bestmm.com/";
        String urlname = basename + filename1 + "/pic/" + filename2 + ".jpg";
        URL url = null;
        try {
            url = new URL(urlname);
        } catch (MalformedURLException e) {
            System.err.println("URL Format Error!");
            System.exit(1);
        }
        try {
            conn = (HttpURLConnection) url.openConnection();
        } catch (IOException e) {
            System.err.println("Error IO");
            System.exit(2);
        }
    }
public void addXMLResources(URL url) throws IOException {
        try {
            Document document = new Builder().build(url.openStream());
            Element root = document.getRootElement();
            if (!root.getLocalName().equals("resources")) throw new IOException("Document root must be <resources>");
            Elements elements = root.getChildElements();
            for (int i = 0; i < elements.size(); i++) {
                Element element = elements.get(i);
                if (element.getLocalName().equals("string")) parseString(element); else if (element.getLocalName().equals("menubar")) parseMenubar(element); else if (element.getLocalName().equals("menu")) parseMenu(element); else if (element.getLocalName().equals("toolbar")) parseToolbar(element); else throw new IOException("Unrecognized element: <" + element.getLocalName() + ">");
            }
        } catch (ParsingException pe) {
            IOException ioe = new IOException(pe.getMessage());
            ioe.initCause(pe);
            throw ioe;
        }
    }
public int create(BusinessObject o) throws DAOException {
        int insert = 0;
        int id = 0;
        Item item = (Item) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("INSERT_ITEM"));
            pst.setString(1, item.getDescription());
            pst.setDouble(2, item.getUnit_price());
            pst.setInt(3, item.getQuantity());
            pst.setDouble(4, item.getVat());
            pst.setInt(5, item.getIdProject());
            pst.setInt(6, item.getIdCurrency());
            insert = pst.executeUpdate();
            if (insert <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (insert > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("select max(id_item) from item");
            rs.next();
            id = rs.getInt(1);
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return id;
    }
public int delete(BusinessObject o) throws DAOException {
        int delete = 0;
        Item item = (Item) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("DELETE_ITEM"));
            pst.setInt(1, item.getId());
            delete = pst.executeUpdate();
            if (delete <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (delete > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return delete;
    }
public int update(BusinessObject o) throws DAOException {
        int update = 0;
        Item item = (Item) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("UPDATE_ITEM"));
            pst.setString(1, item.getDescription());
            pst.setDouble(2, item.getUnit_price());
            pst.setInt(3, item.getQuantity());
            pst.setDouble(4, item.getVat());
            pst.setInt(5, item.getIdProject());
            if (item.getIdBill() == 0) pst.setNull(6, java.sql.Types.INTEGER); else pst.setInt(6, item.getIdBill());
            pst.setInt(7, item.getIdCurrency());
            pst.setInt(8, item.getId());
            System.out.println("item => " + item.getDescription() + " " + item.getUnit_price() + " " + item.getQuantity() + " " + item.getVat() + " " + item.getIdProject() + " " + item.getIdBill() + " " + item.getIdCurrency() + " " + item.getId());
            update = pst.executeUpdate();
            if (update <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (update > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return update;
    }
public In(URL url) {
        try {
            URLConnection site = url.openConnection();
            InputStream is = site.getInputStream();
            scanner = new Scanner(is, charsetName);
            scanner.useLocale(usLocale);
        } catch (IOException ioe) {
            System.err.println("Could not open " + url);
        }
    }
public In(String s) {
        try {
            File file = new File(s);
            if (file.exists()) {
                scanner = new Scanner(file, charsetName);
                scanner.useLocale(usLocale);
                return;
            }
            URL url = getClass().getResource(s);
            if (url == null) {
                url = new URL(s);
            }
            URLConnection site = url.openConnection();
            InputStream is = site.getInputStream();
            scanner = new Scanner(is, charsetName);
            scanner.useLocale(usLocale);
        } catch (IOException ioe) {
            System.err.println("Could not open " + s);
        }
    }
private static String getHashString(String text, String algorithm) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        AssertUtility.notNull(text);
        AssertUtility.notNullAndNotSpace(algorithm);
        MessageDigest md;
        md = MessageDigest.getInstance(algorithm);
        md.update(text.getBytes("UTF-8"), 0, text.length());
        byte[] hash = md.digest();
        return convertToHex(hash);
    }
private static String getBase64(String text, String algorithm) throws NoSuchAlgorithmException {
        AssertUtility.notNull(text);
        AssertUtility.notNullAndNotSpace(algorithm);
        String base64;
        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.update(text.getBytes());
        base64 = new BASE64Encoder().encode(md.digest());
        return base64;
    }
private static String makePrefixDeclarationsWithPrefix_cc(Set<String> missingPrefixes) {
        StringWriter sb = new StringWriter();
        for (Iterator<String> iterator = missingPrefixes.iterator(); iterator.hasNext(); ) {
            String prefix = (String) iterator.next();
            sb.append(prefix);
            if (iterator.hasNext()) {
                sb.append(',');
            }
        }
        String missingPrefixesForPrefix_cc = sb.toString();
        String prefixDeclarations = "";
        if (missingPrefixes.size() > 0) {
            try {
                String urlString = "http://prefix.cc/" + missingPrefixesForPrefix_cc + ".file.n3";
                URL url = new URL(urlString);
                URLConnection conn = url.openConnection();
                conn.setRequestProperty("accept", "application/rdf+n3, application/rdf-turtle, application/rdf-n3," + "text/rdf+n3");
                InputStream openStream = conn.getInputStream();
                StringWriter output = new StringWriter();
                ReaderUtils.copyReader("# From prefix.cc\n", new InputStreamReader(openStream), output);
                prefixDeclarations = output.toString();
                Logger.getLogger("prefix.cc").info("makePrefixDeclarationsWithPrefix_cc() : From prefix.cc:\n" + prefixDeclarations);
            } catch (MalformedURLException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return prefixDeclarations;
    }
public void testCommitRollback() throws Exception {
        Statement stmt = con.createStatement();
        assertNotNull(stmt);
        assertTrue(con.getAutoCommit());
        stmt.execute("CREATE TABLE #TESTCOMMIT (id int primary key)");
        con.setAutoCommit(false);
        assertFalse(con.getAutoCommit());
        assertEquals(1, stmt.executeUpdate("INSERT INTO #TESTCOMMIT VALUES (1)"));
        con.commit();
        assertEquals(1, stmt.executeUpdate("INSERT INTO #TESTCOMMIT VALUES (2)"));
        assertEquals(1, stmt.executeUpdate("INSERT INTO #TESTCOMMIT VALUES (3)"));
        con.rollback();
        assertEquals(1, stmt.executeUpdate("INSERT INTO #TESTCOMMIT VALUES (4)"));
        con.setAutoCommit(true);
        ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM #TESTCOMMIT");
        rs.next();
        assertEquals("commit", 2, rs.getInt(1));
        stmt.close();
    }
public void testSavepoint4() throws Exception {
        Statement stmt = con.createStatement();
        stmt.execute("CREATE TABLE #savepoint4 (data int)");
        stmt.close();
        con.setAutoCommit(false);
        for (int i = 0; i < 3; i++) {
            PreparedStatement pstmt = con.prepareStatement("INSERT INTO #savepoint4 (data) VALUES (?)");
            pstmt.setInt(1, 1);
            assertTrue(pstmt.executeUpdate() == 1);
            Savepoint savepoint = con.setSavepoint();
            assertNotNull(savepoint);
            assertTrue(savepoint.getSavepointId() == 1);
            try {
                savepoint.getSavepointName();
                assertTrue(false);
            } catch (SQLException e) {
            }
            pstmt.setInt(1, 2);
            assertTrue(pstmt.executeUpdate() == 1);
            pstmt.close();
            pstmt = con.prepareStatement("SELECT SUM(data) FROM #savepoint4");
            ResultSet rs = pstmt.executeQuery();
            assertTrue(rs.next());
            assertTrue(rs.getInt(1) == 3);
            assertTrue(!rs.next());
            pstmt.close();
            rs.close();
            con.rollback(savepoint);
            pstmt = con.prepareStatement("SELECT SUM(data) FROM #savepoint4");
            rs = pstmt.executeQuery();
            assertTrue(rs.next());
            assertTrue(rs.getInt(1) == 1);
            assertTrue(!rs.next());
            pstmt.close();
            rs.close();
            con.rollback();
        }
        con.setAutoCommit(true);
    }
public void testParts() throws Exception {
        URL url = getClass().getClassLoader().getResource("de/schlund/pfixxml/parts.xml");
        InputSource source = new InputSource(url.openStream());
        source.setSystemId(url.toString());
        IncludePartsInfo info = IncludePartsInfoParser.parse(source);
        Map<String, IncludePartInfo> parts = info.getParts();
        assertEquals(3, parts.size());
        assertTrue(parts.containsKey("aaa"));
        assertTrue(parts.containsKey("bbb"));
        assertFalse(parts.containsKey("ccc"));
        assertTrue(parts.containsKey("ddd"));
    }
public InputStream getResourceAsStream(String path) {
            try {
                URL url = getResource(path);
                if (url != null) {
                    return url.openStream();
                } else {
                    return null;
                }
            } catch (IOException ioe) {
                return null;
            }
        }
public FetchTextFromWebPage(String path) {
        HTMLEditorKit.Parser parser;
        HTMLFile = new File(path);
        byte[] html = new byte[new Long(HTMLFile.length()).intValue()];
        try {
            FileInputStream fis = new FileInputStream(HTMLFile);
            try {
                fis.read(html);
            } catch (IOException e) {
                e.printStackTrace();
            }
            ByteArrayInputStream ba_read = new ByteArrayInputStream(html);
            r = new InputStreamReader(ba_read);
        } catch (FileNotFoundException e) {
            URL url = null;
            try {
                url = new URL(path);
                URLConnection connection = null;
                try {
                    connection = url.openConnection();
                    connection.setDoInput(true);
                    InputStream inStream = null;
                    try {
                        inStream = connection.getInputStream();
                        BufferedReader input = new BufferedReader(new InputStreamReader(inStream));
                        StringBuffer sbr = new StringBuffer();
                        String line = null;
                        try {
                            while ((line = input.readLine()) != null) {
                                System.out.println(line);
                                sbr.append(line + "\n");
                            }
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                        File temp = new File("//home//wiki14//temp.txt");
                        if (!temp.exists()) {
                            if (!temp.createNewFile()) System.out.println("File caanot be created");
                        } else {
                            temp.delete();
                            if (!temp.createNewFile()) System.out.println("File caanot be created");
                        }
                        java.io.FileWriter fw = new java.io.FileWriter(temp);
                        fw.write(sbr.toString());
                        fw.close();
                        byte[] newbyte = new byte[new Long(sbr.length()).intValue()];
                        ByteArrayInputStream ba_read = new ByteArrayInputStream(newbyte);
                        r = new InputStreamReader(ba_read);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            } catch (MalformedURLException e1) {
                e1.printStackTrace();
            }
        }
        parser = new ParserDelegator();
        htmltextparser = new HtmlTextParser();
        htmltextparser.initData();
        try {
            parser.parse(r, htmltextparser, true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            r.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String openldapDigestMd5(final String password) {
        String base64;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(password.getBytes());
            base64 = fr.cnes.sitools.util.Base64.encodeBytes(digest.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        return OPENLDAP_MD5_PREFIX + base64;
    }
public static boolean writeFileByBinary(InputStream pIs, File pFile, boolean pAppend) {
        boolean flag = false;
        try {
            FileOutputStream fos = new FileOutputStream(pFile, pAppend);
            IOUtils.copy(pIs, fos);
            fos.flush();
            fos.close();
            pIs.close();
            flag = true;
        } catch (Exception e) {
            LOG.error("将字节流写入�?" + pFile.getName() + "出现异常�?", e);
        }
        return flag;
    }
public static boolean writeFileByChars(Reader pReader, File pFile, boolean pAppend) {
        boolean flag = false;
        try {
            FileWriter fw = new FileWriter(pFile, pAppend);
            IOUtils.copy(pReader, fw);
            fw.flush();
            fw.close();
            pReader.close();
            flag = true;
        } catch (Exception e) {
            LOG.error("将字符流写入�?" + pFile.getName() + "出现异常�?", e);
        }
        return flag;
    }
public static boolean writeFileB2C(InputStream pIs, File pFile, boolean pAppend) {
        boolean flag = false;
        try {
            FileWriter fw = new FileWriter(pFile, pAppend);
            IOUtils.copy(pIs, fw);
            fw.flush();
            fw.close();
            pIs.close();
            flag = true;
        } catch (Exception e) {
            LOG.error("将字节流写入�?" + pFile.getName() + "出现异常�?", e);
        }
        return flag;
    }
private void alterarCategoria(Categoria cat) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            conn = C3P0Pool.getConnection();
            String sql = "UPDATE categoria SET nome_categoria = ? where id_categoria = ?";
            ps = conn.prepareStatement(sql);
            ps.setString(1, cat.getNome());
            ps.setInt(2, cat.getCodigo());
            ps.executeUpdate();
            conn.commit();
        } catch (Exception e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            close(conn, ps);
        }
    }