semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void doNew(Vector userId, String shareFlag, String folderId) throws AddrException {
        DBOperation dbo = null;
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet rset = null;
        String sql = "insert into " + SHARE_TABLE + " values(?,?,?)";
        try {
            dbo = createDBOperation();
            connection = dbo.getConnection();
            connection.setAutoCommit(false);
            for (int i = 0; i < userId.size(); i++) {
                String user = (String) userId.elementAt(i);
                ps = connection.prepareStatement(sql);
                ps.setInt(1, Integer.parseInt(folderId));
                ps.setInt(2, Integer.parseInt(user));
                ps.setString(3, shareFlag);
                int resultCount = ps.executeUpdate();
                if (resultCount != 1) {
                    throw new Exception("error");
                }
            }
            connection.commit();
        } catch (Exception ex) {
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            logger.error("���������ļ�����Ϣʧ��, " + ex.getMessage());
            throw new AddrException("���������ļ�����Ϣʧ��,һ�������ļ���ֻ�ܹ����ͬһ�û�һ��!");
        } finally {
            close(rset, null, ps, connection, dbo);
        }
    }
@Override
    public void copyFile2File(final File src, final File dest, final boolean force) throws C4JException {
        if (dest.exists()) if (force && !dest.delete()) throw new C4JException(format("Copying ‘%s’ to ‘%s’ failed; cannot overwrite existing file.", src.getPath(), dest.getPath()));
        FileChannel inChannel = null;
        FileChannel outChannel = null;
        try {
            inChannel = new FileInputStream(src).getChannel();
            outChannel = new FileOutputStream(dest).getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
            if (src.canExecute()) dest.setExecutable(true, false);
        } catch (final IOException e) {
            throw new C4JException(format("Could not copy ‘%s’ to ‘%s’.", src.getPath(), dest.getPath()), e);
        } finally {
            if (inChannel != null) try {
                try {
                    inChannel.close();
                } catch (final IOException e) {
                    throw new C4JException(format("Could not close input stream for ‘%s’.", src.getPath()), e);
                }
            } finally {
                if (outChannel != null) try {
                    outChannel.close();
                } catch (final IOException e) {
                    throw new C4JException(format("Could not close output stream for ‘%s’.", dest.getPath()), e);
                }
            }
        }
    }
public void authenticate(final ConnectionHandler ch, final AuthenticationCriteria ac) throws NamingException {
        byte[] hash = new byte[DIGEST_SIZE];
        try {
            final MessageDigest md = MessageDigest.getInstance(this.passwordScheme);
            md.update(((String) ac.getCredential()).getBytes());
            hash = md.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new NamingException(e.getMessage());
        }
        ch.connect(this.config.getBindDn(), this.config.getBindCredential());
        NamingEnumeration<SearchResult> en = null;
        try {
            en = ch.getLdapContext().search(ac.getDn(), "userPassword={0}", new Object[] { String.format("{%s}%s", this.passwordScheme, LdapUtil.base64Encode(hash)).getBytes() }, LdapConfig.getCompareSearchControls());
            if (!en.hasMore()) {
                throw new AuthenticationException("Compare authentication failed.");
            }
        } finally {
            if (en != null) {
                en.close();
            }
        }
    }
public void connect(final URLConnectAdapter urlAdapter) {
        if (this.connectSettings == null) {
            throw new IllegalStateException("Invalid Connect Settings (is null)");
        }
        final HttpURLConnection httpConnection = (HttpURLConnection) urlAdapter.openConnection();
        BufferedReader in;
        try {
            in = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
            final StringBuilder buf = new StringBuilder(200);
            String str;
            while ((str = in.readLine()) != null) {
                buf.append(str);
                buf.append('\n');
            }
            final ConnectResult result = new ConnectResult(httpConnection.getResponseCode(), buf.toString());
            final Map<String, List<String>> headerFields = httpConnection.getHeaderFields();
            for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) {
                final String key = entry.getKey();
                final List<String> val = entry.getValue();
                if ((val != null) && (val.size() > 1)) {
                    System.out.println("WARN: Invalid header value : " + key + " url=" + this.connectSettings.getUrl());
                }
                if (key != null) {
                    result.addHeader(key, val.get(0), val);
                } else {
                    result.addHeader("Status", val.get(0), val);
                }
            }
            this.lastResult = result;
        } catch (IOException e) {
            throw new ConnectException(e);
        }
    }
public byte[] loadClassFirst(final String className) {
        if (className.startsWith("com.sun.sgs.impl.service.transaction.TransactionCoordinatorImpl")) {
            String resource = null;
            if (className.equals("com.sun.sgs.impl.service.transaction.TransactionCoordinatorImpl")) {
                resource = "com/sun/sgs/impl/service/transaction/TransactionCoordinatorImpl.class.bin";
            }
            if (resource != null) {
                final URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
                if (url != null) {
                    try {
                        return StreamUtil.read(url.openStream());
                    } catch (final IOException e) {
                    }
                }
                throw new IllegalStateException("Unable to load binary class");
            }
        }
        return null;
    }
public boolean delete(int id) {
        boolean deletionOk = false;
        Connection conn = null;
        try {
            conn = db.getConnection();
            conn.setAutoCommit(false);
            String sql = "DELETE FROM keyphrases WHERE website_id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, id);
            deletionOk = ps.executeUpdate() == 1;
            ps.close();
            sql = "DELETE FROM websites WHERE id=?";
            ps = conn.prepareStatement(sql);
            ps.setInt(1, id);
            boolean success = ps.executeUpdate() == 1;
            deletionOk = deletionOk && success;
            ps.close();
            conn.commit();
            conn.setAutoCommit(true);
        } catch (SQLException sqle) {
            try {
                conn.rollback();
                conn.setAutoCommit(true);
            } catch (SQLException sex) {
                throw new OsseoFailure("SQL error: roll back failed. ", sex);
            }
            throw new OsseoFailure("SQL error: cannot remove website with id " + id + ".", sqle);
        } finally {
            db.putConnection(conn);
        }
        return deletionOk;
    }
private WikiSiteContentInfo createInfoIndexSite(Long domainId) {
        final UserInfo user = getSecurityService().getCurrentUser();
        final Locale locale = new Locale(user.getLocale());
        final String country = locale.getLanguage();
        InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wiki_index_" + country + ".xhtml");
        if (inStream == null) {
            inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wiki_index.xhtml");
        }
        if (inStream == null) {
            inStream = new ByteArrayInputStream(DEFAULT_WIKI_INDEX_SITE_TEXT.getBytes());
        }
        if (inStream != null) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                IOUtils.copyLarge(inStream, out);
                return createIndexVersion(domainId, out.toString(), user);
            } catch (IOException exception) {
                LOGGER.error("Error creating info page.", exception);
            } finally {
                try {
                    inStream.close();
                    out.close();
                } catch (IOException exception) {
                    LOGGER.error("Error reading wiki_index.xhtml", exception);
                }
            }
        }
        return null;
    }
private HttpsURLConnection setUpConnection(URL url) throws NoSuchAlgorithmException, KeyManagementException, IOException {
        HttpsURLConnection openConnection = (HttpsURLConnection) url.openConnection();
        openConnection.setAllowUserInteraction(true);
        openConnection.setUseCaches(false);
        openConnection.setDoInput(true);
        openConnection.setDoOutput(true);
        SSLContext sc = SSLContext.getInstance(SSL_PROTOCOL);
        sc.init(new KeyManager[] { new MyKeyManager() }, new TrustManager[] { new BypassTrustManager() }, null);
        openConnection.setSSLSocketFactory(sc.getSocketFactory());
        return openConnection;
    }
public void copyFile(String source_name, String dest_name) throws IOException {
        File source_file = new File(source_name);
        File destination_file = new File(dest_name);
        Reader source = null;
        Writer destination = null;
        char[] buffer;
        int bytes_read;
        try {
            if (!source_file.exists() || !source_file.isFile()) throw new FileCopyException("FileCopy: no such source file: " + source_name);
            if (!source_file.canRead()) throw new FileCopyException("FileCopy: source file " + "is unreadable: " + source_name);
            if (destination_file.exists()) {
                if (destination_file.isFile()) {
                    DataInputStream in = new DataInputStream(System.in);
                    String response;
                    if (!destination_file.canWrite()) throw new FileCopyException("FileCopy: destination " + "file is unwriteable: " + dest_name);
                } else {
                    throw new FileCopyException("FileCopy: destination " + "is not a file: " + dest_name);
                }
            } else {
                File parentdir = parent(destination_file);
                if (!parentdir.exists()) throw new FileCopyException("FileCopy: destination " + "directory doesn't exist: " + dest_name);
                if (!parentdir.canWrite()) throw new FileCopyException("FileCopy: destination " + "directory is unwriteable: " + dest_name);
            }
            source = new BufferedReader(new FileReader(source_file));
            destination = new BufferedWriter(new FileWriter(destination_file));
            buffer = new char[1024];
            while (true) {
                bytes_read = source.read(buffer, 0, 1024);
                if (bytes_read == -1) break;
                destination.write(buffer, 0, bytes_read);
            }
        } finally {
            if (source != null) {
                try {
                    source.close();
                } catch (IOException e) {
                    ;
                }
            }
            if (destination != null) {
                try {
                    destination.close();
                } catch (IOException e) {
                    ;
                }
            }
        }
    }
private 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);
    }
public Result search(Object object) {
        if (object == null || !(object instanceof String)) {
            return null;
        }
        String query = (String) object;
        Result hitResult = new Result();
        Set<Hit> hits = new HashSet<Hit>(8);
        try {
            query = URLEncoder.encode(query, "UTF-8");
            URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?start=0&rsz=large&v=1.0&q=" + query);
            URLConnection connection = url.openConnection();
            connection.addRequestProperty("Referer", HTTP_REFERER);
            String line;
            StringBuilder builder = new StringBuilder();
            InputStream input = connection.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            input.close();
            String response = builder.toString();
            JSONObject json = new JSONObject(response);
            LOGGER.debug(json.getString("responseData"));
            int count = json.getJSONObject("responseData").getJSONObject("cursor").getInt("estimatedResultCount");
            hitResult.setEstimatedCount(count);
            JSONArray ja = json.getJSONObject("responseData").getJSONArray("results");
            for (int i = 0; i < ja.length(); i++) {
                JSONObject j = ja.getJSONObject(i);
                Hit hit = new Hit();
                String result = j.getString("titleNoFormatting");
                hit.setTitle(result == null || result.equals("") ? "${EMPTY}" : result);
                result = j.getString("url");
                hit.setUrl(new URL(result));
                hits.add(hit);
            }
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("Something went wrong..." + e.getMessage());
        }
        hitResult.setHits(hits);
        return hitResult;
    }
@Override
    @RemoteMethod
    public boolean encrypt(int idAnexo) {
        try {
            Anexo anexo = anexoService.selectById(idAnexo);
            aes.init(Cipher.ENCRYPT_MODE, aeskeySpec);
            FileInputStream fis = new FileInputStream(config.baseDir + "/arquivos_upload_direto/" + anexo.getAnexoCaminho());
            CipherOutputStream cos = new CipherOutputStream(new FileOutputStream(config.baseDir + "/arquivos_upload_direto/encrypt/" + anexo.getAnexoCaminho()), aes);
            IOUtils.copy(fis, cos);
            cos.close();
            fis.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
@Override
    @RemoteMethod
    public boolean decrypt(int idAnexo) {
        try {
            Anexo anexo = anexoService.selectById(idAnexo);
            aes.init(Cipher.DECRYPT_MODE, aeskeySpec);
            CipherInputStream cis = new CipherInputStream(new FileInputStream(config.baseDir + "/arquivos_upload_direto/encrypt/" + anexo.getAnexoCaminho()), aes);
            FileOutputStream fos = new FileOutputStream(config.baseDir + "/arquivos_upload_direto/decrypt/" + anexo.getAnexoCaminho());
            IOUtils.copy(cis, fos);
            cis.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public String getText() throws IOException {
        InputStreamReader r = new InputStreamReader(getInputStream(), encoding);
        StringWriter w = new StringWriter(256 * 128);
        try {
            IOUtils.copy(r, w);
        } finally {
            IOUtils.closeQuietly(w);
            IOUtils.closeQuietly(r);
        }
        return w.toString();
    }
public static org.osid.repository.AssetIterator search(Repository repository, SearchCriteria lSearchCriteria) throws org.osid.repository.RepositoryException {
        try {
            NodeList fieldNode = null;
            if (lSearchCriteria.getSearchOperation() == SearchCriteria.FIND_OBJECTS) {
                URL url = new URL("http", repository.getAddress(), repository.getPort(), SEARCH_STRING + URLEncoder.encode(lSearchCriteria.getKeywords() + WILDCARD, "ISO-8859-1"));
                XPathFactory factory = XPathFactory.newInstance();
                XPath xPath = factory.newXPath();
                xPath.setNamespaceContext(new FedoraNamespaceContext());
                InputSource inputSource = new InputSource(url.openStream());
                fieldNode = (NodeList) xPath.evaluate("/pre:result/pre:resultList/pre:objectFields", inputSource, XPathConstants.NODESET);
                if (fieldNode.getLength() > 0) {
                    inputSource = new InputSource(url.openStream());
                    XPathExpression xSession = xPath.compile("//pre:token/text()");
                    String token = xSession.evaluate(inputSource);
                    lSearchCriteria.setToken(token);
                }
            }
            return getAssetIterator(repository, fieldNode);
        } catch (Throwable t) {
            throw wrappedException("search", t);
        }
    }
public void generate(String rootDir, RootModel root) throws Exception {
        IOUtils.copyStream(HTMLGenerator.class.getResourceAsStream("stylesheet.css"), new FileOutputStream(new File(rootDir, "stylesheet.css")));
        Velocity.init();
        VelocityContext context = new VelocityContext();
        context.put("model", root);
        context.put("util", new VelocityUtils());
        context.put("msg", messages);
        processTemplate("index.html", new File(rootDir, "index.html"), context);
        processTemplate("list.html", new File(rootDir, "list.html"), context);
        processTemplate("summary.html", new File(rootDir, "summary.html"), context);
        File imageDir = new File(rootDir, "images");
        imageDir.mkdir();
        IOUtils.copyStream(HTMLGenerator.class.getResourceAsStream("primarykey.gif"), new FileOutputStream(new File(imageDir, "primarykey.gif")));
        File tableDir = new File(rootDir, "tables");
        tableDir.mkdir();
        for (TableModel table : root.getTables()) {
            context.put("table", table);
            processTemplate("table.html", new File(tableDir, table.getTableName() + ".html"), context);
        }
    }
public static void parseString(String str, String name) {
        BufferedReader reader;
        String zeile = null;
        boolean firstL = true;
        int lambda;
        float intens;
        int l_b = 0;
        int l_e = 0;
        HashMap<Integer, Float> curve = new HashMap<Integer, Float>();
        String[] temp;
        try {
            File f = File.createTempFile("tempFile", null);
            URL url = new URL(str);
            InputStream is = url.openStream();
            FileOutputStream os = new FileOutputStream(f);
            byte[] buffer = new byte[0xFFFF];
            for (int len; (len = is.read(buffer)) != -1; ) os.write(buffer, 0, len);
            is.close();
            os.close();
            reader = new BufferedReader(new FileReader(f));
            zeile = reader.readLine();
            lambda = 0;
            while (zeile != null) {
                if (!(zeile.length() > 0 && zeile.charAt(0) == '#')) {
                    zeile = reader.readLine();
                    break;
                }
                zeile = reader.readLine();
            }
            while (zeile != null) {
                if (zeile.length() > 0) {
                    temp = zeile.split(" ");
                    lambda = Integer.parseInt(temp[0]);
                    intens = Float.parseFloat(temp[1]);
                    if (firstL) {
                        firstL = false;
                        l_b = lambda;
                    }
                    curve.put(lambda, intens);
                }
                zeile = reader.readLine();
            }
            l_e = lambda;
        } catch (IOException e) {
            System.err.println("Error2 :" + e);
        }
        try {
            String tempV;
            File file = new File("C:/spectralColors/" + name + ".sd");
            FileWriter fw = new FileWriter(file);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write("# COLOR: " + name + " Auto generated File: 02/09/2009; From " + l_b + " to " + l_e);
            bw.newLine();
            bw.write(l_b + "");
            bw.newLine();
            for (int i = l_b; i <= l_e; i++) {
                if (curve.containsKey(i)) {
                    tempV = i + " " + curve.get(i);
                    bw.write(tempV);
                    bw.newLine();
                }
            }
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public I18N(JApplet applet) {
        if (prop != null) {
            return;
        }
        String lang = "de";
        try {
            Properties userProperties = new Properties();
            if (applet != null) {
                URL url = new URL(applet.getCodeBase() + xConfigPath + "ElementDesigner.cfg");
                userProperties.load(url.openStream());
            } else {
                userProperties.load(new FileInputStream(xConfigPath + "ElementDesigner.cfg"));
            }
            if (userProperties.containsKey("language")) {
                lang = userProperties.getProperty("language");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        prop = new Properties();
        try {
            if (applet != null) {
                URL url = new URL(applet.getCodeBase() + xLanguagePath + lang + ".ini");
                prop.load(url.openStream());
            } else {
                prop.load(new FileInputStream(xLanguagePath + lang + ".ini"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            try {
                if (applet != null) {
                    URL url = new URL(applet.getCodeBase() + xLanguagePath + "de.ini");
                    prop.load(url.openStream());
                } else {
                    prop.load(new FileInputStream(xLanguagePath + "de.ini"));
                }
            } catch (Exception ex2) {
                JOptionPane.showMessageDialog(null, "Language file languages/de.ini not found.\nPlease run the program from its directory.");
                System.exit(5);
            }
        }
    }