semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public boolean delwuliao(String pid) {
        boolean flag = false;
        Connection conn = null;
        PreparedStatement pm = null;
        try {
            conn = Pool.getConnection();
            conn.setAutoCommit(false);
            pm = conn.prepareStatement("delete from addwuliao where pid=?");
            pm.setString(1, pid);
            int x = pm.executeUpdate();
            if (x == 0) {
                flag = false;
            } else {
                flag = true;
            }
            conn.commit();
            Pool.close(pm);
            Pool.close(conn);
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            Pool.close(pm);
            Pool.close(conn);
        } finally {
            Pool.close(pm);
            Pool.close(conn);
        }
        return flag;
    }
public Item findById(String itemId) throws UnsupportedEncodingException, IOException {
        String sessionId = (String) RuntimeAccess.getInstance().getSession().getAttribute("SESSION_ID");
        DefaultHttpClient httpclient = new DefaultHttpClient();
        FindItemByIdRequest request = new FindItemByIdRequest();
        request.setItemID(itemId);
        request.setSessionId(sessionId);
        XStream writer = new XStream();
        writer.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        writer.alias("FindItemByIdRequest", FindItemByIdRequest.class);
        XStream reader = new XStream();
        reader.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        reader.alias("FindItemByIdResponse", FindItemByIdResponse.class);
        String strRequest = URLEncoder.encode(reader.toXML(request), "UTF-8");
        HttpGet httpget = new HttpGet(MewitProperties.getMewitUrl() + "/resources/findItemById?REQUEST=" + strRequest);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = URLDecoder.decode(EntityUtils.toString(entity), "UTF-8");
            FindItemByIdResponse fibiResponse = (FindItemByIdResponse) reader.fromXML(result);
            return fibiResponse.getItem();
        }
        return null;
    }
public QueryResult doSearch(String searchTerm, Integer searchInReceivedItems, Integer searchInSentItems, Integer searchInSupervisedItems, Integer startRow, Integer resultCount, Boolean searchArchived, Boolean searchInItemsNeededAttentionOnly) throws UnsupportedEncodingException, IOException {
        String sessionId = (String) RuntimeAccess.getInstance().getSession().getAttribute("SESSION_ID");
        DefaultHttpClient httpclient = new DefaultHttpClient();
        QueryResult queryResult = new QueryResult();
        SearchRequest request = new SearchRequest();
        SearchItemsQuery query = new SearchItemsQuery();
        query.setArchiveIncluded(searchArchived);
        log(INFO, "searchTerm=" + searchTerm);
        log(INFO, "search in received=" + searchInReceivedItems);
        log(INFO, "search in sent=" + searchInSentItems);
        log(INFO, "search in supervised=" + searchInSupervisedItems);
        List<String> filters = new ArrayList<String>();
        if (searchInItemsNeededAttentionOnly == false) {
            if (searchInReceivedItems != null) {
                filters.add("ALL_RECEIVED_ITEMS");
            }
            if (searchInSentItems != null) {
                filters.add("ALL_SENT_ITEMS");
            }
            if (searchInSupervisedItems != null) {
                filters.add("ALL_SUPERVISED_ITEMS");
            }
        } else {
            if (searchInReceivedItems != null) {
                filters.add("RECEIVED_ITEMS_NEEDED_ATTENTION");
            }
            if (searchInSentItems != null) {
                filters.add("SENT_ITEMS_NEEDED_ATTENTION");
            }
        }
        query.setFilters(filters);
        query.setId("1234");
        query.setOwner(sessionId);
        query.setReferenceOnly(false);
        query.setSearchTerm(searchTerm);
        query.setUseOR(false);
        request.setStartRow(startRow);
        request.setResultCount(resultCount);
        request.setQuery(query);
        request.setSessionId(sessionId);
        XStream writer = new XStream();
        writer.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        writer.alias("SearchRequest", SearchRequest.class);
        XStream reader = new XStream();
        reader.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        reader.alias("SearchResponse", SearchResponse.class);
        String strRequest = URLEncoder.encode(reader.toXML(request), "UTF-8");
        HttpGet httpget = new HttpGet(MewitProperties.getMewitUrl() + "/resources/search?REQUEST=" + strRequest);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = URLDecoder.decode(EntityUtils.toString(entity), "UTF-8");
            SearchResponse searchResponse = (SearchResponse) reader.fromXML(result);
            List<Item> items = searchResponse.getItems();
            queryResult.setItems(items);
            queryResult.setTotal(searchResponse.getTotalResultCount());
            queryResult.setStartRow(searchResponse.getStartRow());
        }
        return queryResult;
    }
public boolean checkPassword(String password, String digest) {
        boolean passwordMatch = false;
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA-1");
            if (digest.regionMatches(true, 0, "{SHA}", 0, 5)) {
                digest = digest.substring(5);
            } else if (digest.regionMatches(true, 0, "{SSHA}", 0, 6)) {
                digest = digest.substring(6);
            }
            byte[][] hs = split(Base64.decode(digest.getBytes()), 20);
            byte[] hash = hs[0];
            byte[] salt = hs[1];
            sha.reset();
            sha.update(password.getBytes());
            sha.update(salt);
            byte[] pwhash = sha.digest();
            if (MessageDigest.isEqual(hash, pwhash)) {
                passwordMatch = true;
            }
        } catch (NoSuchAlgorithmException nsae) {
            CofaxToolsUtil.log("Algorithme SHA-1 non supporte a la verification du password" + nsae + id);
        }
        return passwordMatch;
    }
public static String getSSHADigest(String password, String salt) {
        String digest = null;
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA-1");
            sha.reset();
            sha.update(password.getBytes());
            sha.update(salt.getBytes());
            byte[] pwhash = sha.digest();
            digest = "{SSHA}" + new String(Base64.encode(concatenate(pwhash, salt.getBytes())));
        } catch (NoSuchAlgorithmException nsae) {
            CofaxToolsUtil.log("Algorithme SHA-1 non supporte a la creation du hashage" + nsae + id);
        }
        return digest;
    }
public static String getSHADigest(String password) {
        String digest = null;
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA-1");
            sha.reset();
            sha.update(password.getBytes());
            byte[] pwhash = sha.digest();
            digest = "{SHA}" + new String(Base64.encode(pwhash));
        } catch (NoSuchAlgorithmException nsae) {
            CofaxToolsUtil.log("Algorithme SHA-1 non supporte a la creation du hashage" + nsae + id);
        }
        return digest;
    }
public static void copyFromTo(File srcFile, File destFile) {
        FileChannel in = null, out = null;
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(srcFile);
        } catch (FileNotFoundException fnfe) {
            System.out.println("File: " + srcFile.toString());
            System.out.println("file does not exist, " + "is a directory rather than a regular file, " + "or for some other reason cannot be opened for reading");
            System.exit(-1);
        }
        try {
            fos = new FileOutputStream(destFile);
        } catch (FileNotFoundException fnfe) {
            System.out.println("File: " + destFile.toString());
            System.out.println("file exists but is a directory rather than a regular file, " + "does not exist but cannot be created, " + "or cannot be opened for any other reason");
            System.exit(-1);
        }
        try {
            in = fis.getChannel();
            out = fos.getChannel();
            in.transferTo(0, in.size(), out);
            fos.flush();
            fos.close();
            out.close();
            fis.close();
            in.close();
            System.out.println("Completed copying " + srcFile.toString() + " to " + destFile.toString());
        } catch (IOException ioe) {
            System.out.println("IOException copying file: " + ioe.getMessage());
            System.exit(-1);
        }
        long srcModified = srcFile.lastModified();
        if (srcModified > 0L && destFile.exists()) {
            destFile.setLastModified(srcModified);
        }
    }
public void setContentAsStream(final InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try {
            IOUtils.copy(input, output);
        } finally {
            output.close();
        }
        this.content = output.toByteArray();
    }
private String unJar(String jarPath, String jarEntry) {
        String path;
        if (jarPath.lastIndexOf("lib/") >= 0) path = jarPath.substring(0, jarPath.lastIndexOf("lib/")); else path = jarPath.substring(0, jarPath.lastIndexOf("/"));
        String relPath = jarEntry.substring(0, jarEntry.lastIndexOf("/"));
        try {
            new File(path + "/" + relPath).mkdirs();
            JarFile jar = new JarFile(jarPath);
            ZipEntry ze = jar.getEntry(jarEntry);
            File bin = new File(path + "/" + jarEntry);
            IOUtils.copy(jar.getInputStream(ze), new FileOutputStream(bin));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return path + "/" + jarEntry;
    }
public alto.io.Output openOutput() throws java.io.IOException {
        URL url = this.url;
        if (null != url) {
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            if (connection instanceof alto.net.Connection) {
                ((alto.net.Connection) connection).setReference(this);
            }
            return new ReferenceOutputStream(this, connection);
        }
        HttpMessage container = this.write();
        return new ReferenceOutputStream(this, container);
    }
public void insertComponent() throws SQLException {
        Connection connection = null;
        PreparedStatement ps = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = (Connection) DriverManager.getConnection(this.jdbcURL);
            connection.setAutoCommit(false);
            String query = "INSERT INTO components(name,rate,quantity, description) VALUES(?,?,?,?)";
            ps = (PreparedStatement) connection.prepareStatement(query);
            ps.setString(1, this.name);
            ps.setDouble(2, this.rate);
            ps.setInt(3, this.quantity);
            ps.setString(4, this.description);
            ps.executeUpdate();
            connection.commit();
        } catch (Exception ex) {
            connection.rollback();
        } finally {
            try {
                connection.close();
            } catch (Exception ex) {
            }
            try {
                ps.close();
            } catch (Exception ex) {
            }
        }
    }
public void updateComponent(int id, int quantity) throws SQLException {
        Connection connection = null;
        PreparedStatement ps = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = (Connection) DriverManager.getConnection(this.jdbcURL);
            connection.setAutoCommit(false);
            String query = "UPDATE components SET quantity=quantity+? WHERE comp_id=?";
            ps = connection.prepareStatement(query);
            ps.setInt(1, quantity);
            ps.setInt(2, id);
            ps.executeUpdate();
            connection.commit();
        } catch (Exception ex) {
            connection.rollback();
        } finally {
            try {
                connection.close();
            } catch (Exception ex) {
            }
            try {
                ps.close();
            } catch (Exception ex) {
            }
        }
    }
public he3Decode(String in_file) {
        try {
            File out = new File(in_file + extension);
            File in = new File(in_file);
            int file_size = (int) in.length();
            FileInputStream in_stream = new FileInputStream(in_file);
            out.createNewFile();
            FileOutputStream out_stream = new FileOutputStream(out.getName());
            ByteArrayOutputStream os = new ByteArrayOutputStream(file_size);
            byte byte_arr[] = new byte[8];
            int buff_size = byte_arr.length;
            int _fetched = 0;
            int _chars_read = 0;
            System.out.println(appname + ".\n" + "decoding: " + in_file + "\n" + "decoding to: " + in_file + extension + "\n" + "\nreading: ");
            while (_fetched < file_size) {
                _chars_read = in_stream.read(byte_arr, 0, buff_size);
                if (_chars_read == -1) break;
                os.write(byte_arr, 0, _chars_read);
                _fetched += _chars_read;
                System.out.print("*");
            }
            System.out.print("\ndecoding: ");
            out_stream.write(_decode((ByteArrayOutputStream) os));
            System.out.print("complete\n\n");
        } catch (java.io.FileNotFoundException fnfEx) {
            System.err.println("Exception: " + fnfEx.getMessage());
        } catch (java.io.IOException ioEx) {
            System.err.println("Exception: " + ioEx.getMessage());
        }
    }
public ForkJavaProject(String projectName, Class<?> activatorClass) {
        this.activatorClass = activatorClass;
        try {
            IWorkspaceRoot rootWorkspace = ResourcesPlugin.getWorkspace().getRoot();
            this.prj = rootWorkspace.getProject(projectName);
            if (this.prj.exists()) {
                this.prj.delete(true, true, new NullProgressMonitor());
            }
            this.prj.create(new NullProgressMonitor());
            this.prj.open(new NullProgressMonitor());
            IProjectDescription description = this.prj.getDescription();
            description.setNatureIds(new String[] { "org.eclipse.jdt.core.javanature" });
            this.prj.setDescription(description, new NullProgressMonitor());
            createProjectDir(Constants.Dirs.DIR_MAIN_JAVA);
            createProjectDir(Constants.Dirs.DIR_CONFIG);
            createProjectDir(Constants.Dirs.DIR_MAIN_RESOURCES);
            createProjectDir(Constants.Dirs.DIR_MODELS);
            createProjectDir(Constants.Dirs.DIR_TESTS_JAVA);
            createProjectDir(Constants.Dirs.DIR_TESTS_RESOURCES);
            createProjectDir(Constants.Dirs.DIR_CLASSES);
            createProjectDir(Constants.Dirs.DIR_LIB);
            this.prj.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
            this.javaProject = JavaCore.create(this.prj);
            if (this.javaProject.exists() && !this.javaProject.isOpen()) {
                this.javaProject.open(new NullProgressMonitor());
            }
            File javaHome = new File(System.getProperty("java.home"));
            IPath jreLibPath = new Path(javaHome.getPath()).append("lib").append("rt.jar");
            this.javaProject.setOutputLocation(prj.getFolder(Constants.Dirs.DIR_CLASSES).getFullPath(), new NullProgressMonitor());
            JavaCore.setClasspathVariable("JRE_LIB", jreLibPath, new NullProgressMonitor());
            this.javaProject.setRawClasspath(getProjectClassPath(), new NullProgressMonitor());
        } catch (CoreException e) {
            Activator.getDefault().logError("An exception has been thrown while creating Project", e);
        }
    }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        session = request.getSession(true);
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String searchTerm = new String();
            if (request.getParameter("searchdb") != null) {
                searchTerm = request.getParameter("searchdb");
                out.write("<ul>");
                PreparedStatement sqlGetLikeBaseString = conn.prepareStatement("SELECT * FROM ENTRIES WHERE XTM_SESSION_ID = ? AND XTM_TEXT LIKE ?");
                sqlGetLikeBaseString.setString(1, session.getId());
                sqlGetLikeBaseString.setString(2, new String("%" + searchTerm + "%"));
                ResultSet res = sqlGetLikeBaseString.executeQuery();
                while (res.next()) {
                    out.write("<li>");
                    out.write(res.getString("XTM_TEXT"));
                    out.write("</li>");
                }
                out.write("</ul>");
                res.close();
            }
            if (request.getParameter("searchwiki") != null) {
                searchTerm = request.getParameter("searchwiki");
                out.write("<ul>");
                try {
                    searchTerm = URLEncoder.encode(searchTerm, "UTF-8");
                    URL url = new URL("http://www.wikipedia.de/suggest.php?lang=de&search=" + searchTerm);
                    URLConnection con = url.openConnection();
                    BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
                    String line;
                    while ((line = rd.readLine()) != null) {
                        out.write("<li>");
                        String[] split = line.split("\t");
                        out.write(split[0]);
                        out.write("</li>");
                    }
                    rd.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                out.write("</ul>");
            } else {
                return;
            }
        } catch (SQLException e) {
            out.println("Caught SQLException:" + e.getMessage());
        }
        ;
    }
private static void setEnvEntry(File fromEAR, File toEAR, String ejbJarName, String envEntryName, String envEntryValue) throws Exception {
        ZipInputStream earFile = new ZipInputStream(new FileInputStream(fromEAR));
        FileOutputStream fos = new FileOutputStream(toEAR);
        ZipOutputStream tempZip = new ZipOutputStream(fos);
        ZipEntry next = earFile.getNextEntry();
        while (next != null) {
            ByteArrayOutputStream content = new ByteArrayOutputStream();
            byte[] data = new byte[30000];
            int numberread;
            while ((numberread = earFile.read(data)) != -1) {
                content.write(data, 0, numberread);
            }
            if (next.getName().equals(ejbJarName)) {
                content = editEJBJAR(next, content, envEntryName, envEntryValue);
                next = new ZipEntry(ejbJarName);
            }
            tempZip.putNextEntry(next);
            tempZip.write(content.toByteArray());
            next = earFile.getNextEntry();
        }
        earFile.close();
        tempZip.close();
        fos.close();
    }
public void test3() throws FileNotFoundException, IOException {
        Decoder decoder1 = new MP3Decoder(new FileInputStream("/home/marc/tmp/test1.mp3"));
        Decoder decoder2 = new OggDecoder(new FileInputStream("/home/marc/tmp/test1.ogg"));
        FileOutputStream out = new FileOutputStream("/home/marc/tmp/test.pipe");
        IOUtils.copy(decoder1, out);
        IOUtils.copy(decoder2, out);
    }
public static void main(String[] args) throws IOException {
        MSPack pack = new MSPack(new FileInputStream(args[0]));
        String[] files = pack.getFileNames();
        for (int i = 0; i < files.length; i++) System.out.println(i + ": " + files[i] + ": " + pack.getLengths()[i]);
        System.out.println("Writing " + files[files.length - 1]);
        InputStream is = pack.getInputStream(files.length - 1);
        OutputStream os = new FileOutputStream(files[files.length - 1]);
        int n;
        byte[] buf = new byte[4096];
        while ((n = is.read(buf)) != -1) os.write(buf, 0, n);
        os.close();
        is.close();
    }
private static String hash(String string) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (Exception e) {
            return null;
        }
        try {
            md.update(string.getBytes("UTF-8"));
        } catch (Exception e) {
            return null;
        }
        byte raw[] = md.digest();
        return (new BASE64Encoder()).encode(raw);
    }
public void createJAR(String fileString, String ext) {
        try {
            File file = new File(fileString);
            int i = fileString.lastIndexOf(java.io.File.separator);
            String dir = fileString.substring(0, i + 1);
            if (ext.matches("jar")) {
                jarFile = new File(getClass().getClassLoader().getResource("jsdviewer.jar").toURI());
                java.io.FileOutputStream fstrm = new java.io.FileOutputStream(file);
                FileChannel in = (new java.io.FileInputStream(jarFile)).getChannel();
                FileChannel out = fstrm.getChannel();
                in.transferTo(0, jarFile.length(), out);
                in.close();
                out.close();
            } else {
                file.mkdir();
            }
            File.umount(file);
            File temp = new File(dir + "document.jsd");
            FileOutputStream fstrm2 = new FileOutputStream(temp.getCanonicalPath());
            ostrm = new ObjectOutputStream(fstrm2);
            ostrm.writeObject(doc);
            ostrm.flush();
            ostrm.close();
            File.umount();
            File docFile = new File(file.getCanonicalPath() + java.io.File.separator + "document.jsd");
            File.cp_p(temp, docFile);
            File.umount();
            temp.delete();
            File.umount(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public HttpResponse execute(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException {
        if (request == null) {
            throw new IllegalArgumentException("HTTP request may not be null");
        }
        if (conn == null) {
            throw new IllegalArgumentException("Client connection may not be null");
        }
        if (context == null) {
            throw new IllegalArgumentException("HTTP context may not be null");
        }
        try {
            HttpResponse response = doSendRequest(request, conn, context);
            if (response == null) {
                response = doReceiveResponse(request, conn, context);
            }
            return response;
        } catch (IOException ex) {
            conn.close();
            throw ex;
        } catch (HttpException ex) {
            conn.close();
            throw ex;
        } catch (RuntimeException ex) {
            conn.close();
            throw ex;
        }
    }
private void writeToUrl(byte[] data, String url) throws IOException, MalformedURLException {
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        OutputStream out = connection.getOutputStream();
        out.write(data);
        out.flush();
        out.close();
    }