semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void copyFromZip(File zipFile) throws GLMRessourceManagerException {
        if (zipFile == null) throw new GLMRessourceZIPException(1);
        if (!zipFile.exists()) throw new GLMRessourceZIPException(2);
        int len = 0;
        byte[] buffer = ContentManager.getDefaultBuffer();
        try {
            ZipInputStream zip_in = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
            ZipEntry zipEntry;
            File rootDir = null;
            while ((zipEntry = zip_in.getNextEntry()) != null) {
                File destFile = new File(tempDirectory, zipEntry.getName());
                if (rootDir == null) rootDir = destFile.getParentFile();
                if (!zipEntry.isDirectory() && destFile.getParentFile().equals(rootDir)) {
                    if (!zipEntry.getName().equals(ContentManager.IMS_MANIFEST_FILENAME)) {
                        FileOutputStream file_out = new FileOutputStream(new File(tempDirectory, zipEntry.getName()));
                        while ((len = zip_in.read(buffer)) > 0) file_out.write(buffer, 0, len);
                        file_out.flush();
                        file_out.close();
                    }
                }
            }
            zip_in.close();
        } catch (Exception e) {
            throw new GLMRessourceZIPException(3);
        }
    }
private final String encryptPassword(String pass) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            log.log(Level.WARNING, "Error while obtaining decript algorithm", e);
            throw new RuntimeException("AccountData.encryptPassword()");
        }
        try {
            md.update(pass.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            log.log(Level.WARNING, "Problem with decript algorithm occured.", e);
            throw new RuntimeException("AccountData.encryptPassword()");
        }
        return new BASE64Encoder().encode(md.digest());
    }
private void getImage(String filename) throws MalformedURLException, IOException, SAXException, FileNotFoundException {
        String url = Constants.STRATEGICDOMINATION_URL + "/images/gameimages/" + filename;
        WebRequest req = new GetMethodWebRequest(url);
        WebResponse response = wc.getResponse(req);
        File file = new File("etc/images/" + filename);
        FileOutputStream outputStream = new FileOutputStream(file);
        IOUtils.copy(response.getInputStream(), outputStream);
    }
protected byte[] retrieveImageData() throws IOException {
        URL url = new URL(imageUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        int fileSize = connection.getContentLength();
        if (fileSize < 0) {
            return null;
        }
        byte[] imageData = new byte[fileSize];
        BufferedInputStream istream = new BufferedInputStream(connection.getInputStream(), 8192);
        int bytesRead = 0;
        int offset = 0;
        while (bytesRead != -1 && offset < fileSize) {
            bytesRead = istream.read(imageData, offset, fileSize - offset);
            offset += bytesRead;
        }
        istream.close();
        connection.disconnect();
        return imageData;
    }
public Configuration load(URL url) throws ConfigurationException {
        LOG.info("Configuring from url : " + url.toString());
        try {
            return load(url.openStream(), url.toString());
        } catch (IOException ioe) {
            throw new ConfigurationException("Could not configure from URL : " + url, ioe);
        }
    }
private void copy(final File src, final File dstDir) {
        dstDir.mkdirs();
        final File dst = new File(dstDir, src.getName());
        BufferedReader reader = null;
        BufferedWriter writer = null;
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(src), "ISO-8859-1"));
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dst), "ISO-8859-1"));
            String read;
            while ((read = reader.readLine()) != null) {
                Line line = new Line(read);
                if (line.isComment()) continue;
                writer.write(read);
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) try {
                reader.close();
            } catch (IOException e) {
            }
            if (writer != null) {
                try {
                    writer.flush();
                } catch (IOException e) {
                }
                try {
                    writer.close();
                } catch (IOException e) {
                }
            }
        }
    }
private static void loadListFromRecouces(String category, URL url, DataSetArray<DataSetList> list, final StatusLineManager slm) {
        i = 0;
        try {
            if (url == null) return;
            InputStream in = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF8"));
            String strLine;
            while ((strLine = br.readLine()) != null) {
                strLine = strLine.trim();
                i++;
                if (slm != null) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            slm.setMessage(_("Importing country code " + i));
                        }
                    });
                }
                if (!strLine.isEmpty() && !strLine.startsWith("#")) {
                    String parts[] = strLine.split("=", 2);
                    if (parts.length == 2) {
                        String key = parts[0].trim();
                        String value = parts[1].trim();
                        key = DataUtils.replaceAllAccentedChars(key).toUpperCase();
                        DataSetList newListEntry = new DataSetList(category, key, value);
                        list.addNewDataSetIfNew(newListEntry);
                    }
                }
            }
            in.close();
        } catch (IOException e) {
            Logger.logError(e, "Error loading " + url.getFile());
        }
    }
private void download(Downloadable downloadable, HttpServletResponse response) throws Exception {
        String contentType = downloadable.getContentType();
        try {
            response.setContentType(contentType);
            response.setHeader("Content-Disposition", "attachment;" + " filename=" + new String(downloadable.getName().getBytes(), "ISO-8859-1"));
            OutputStream os = response.getOutputStream();
            IOUtils.copy(downloadable.getInputStream(), os);
            os.flush();
        } catch (IOException e) {
        }
    }
protected HttpURLConnection loadTileFromOsm(Tile tile) throws IOException {
        URL url;
        url = new URL(tile.getUrl());
        HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
        prepareHttpUrlConnection(urlConn);
        urlConn.setReadTimeout(30000);
        return urlConn;
    }
private static InputStream stream(String input) {
        try {
            if (input.startsWith("http://")) return URIFactory.url(input).openStream(); else return stream(new File(input));
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
public static String genetateSHA256(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(password.getBytes("UTF-8"));
        byte[] passWd = md.digest();
        String hex = toHex(passWd);
        return hex;
    }
public void handleMessage(Message message) throws Fault {
        InputStream is = message.getContent(InputStream.class);
        if (is == null) {
            return;
        }
        CachedOutputStream bos = new CachedOutputStream();
        try {
            IOUtils.copy(is, bos);
            is.close();
            bos.close();
            sendMsg("Inbound Message \n" + "--------------" + bos.getOut().toString() + "\n--------------");
            message.setContent(InputStream.class, bos.getInputStream());
        } catch (IOException e) {
            throw new Fault(e);
        }
    }
public static boolean loadTestProperties(Properties props, Class<?> callingClazz, Class<?> hierarchyRootClazz, String resourceBaseName) {
        if (!hierarchyRootClazz.isAssignableFrom(callingClazz)) {
            throw new IllegalArgumentException("Class " + callingClazz + " is not derived from " + hierarchyRootClazz);
        }
        if (null == resourceBaseName) {
            throw new NullPointerException("resourceBaseName is null");
        }
        String fqcn = callingClazz.getName();
        String uqcn = fqcn.substring(fqcn.lastIndexOf('.') + 1);
        String callingClassResource = uqcn + ".properties";
        String globalCallingClassResource = "/" + callingClassResource;
        String baseClassResource = resourceBaseName + "-" + uqcn + ".properties";
        String globalBaseClassResource = "/" + baseClassResource;
        String pkgResource = resourceBaseName + ".properties";
        String globalResource = "/" + pkgResource;
        boolean loaded = false;
        final String[] resources = { baseClassResource, globalBaseClassResource, callingClassResource, globalCallingClassResource, pkgResource, globalResource };
        List<URL> urls = new ArrayList<URL>();
        Class<?> clazz = callingClazz;
        do {
            for (String res : resources) {
                URL url = clazz.getResource(res);
                if (null != url && !urls.contains(url)) {
                    urls.add(url);
                }
            }
            if (hierarchyRootClazz.equals(clazz)) {
                clazz = null;
            } else {
                clazz = clazz.getSuperclass();
            }
        } while (null != clazz);
        ListIterator<URL> it = urls.listIterator(urls.size());
        while (it.hasPrevious()) {
            URL url = it.previous();
            InputStream in = null;
            try {
                LOG.info("Loading test properties from resource: " + url);
                in = url.openStream();
                props.load(in);
                loaded = true;
            } catch (IOException ex) {
                LOG.warn("Failed to load properties from resource: " + url, ex);
            }
            IOUtil.closeSilently(in);
        }
        return loaded;
    }
public static void signalServer(String solrHostURL) throws IOException {
        if (solrHostURL == null || solrHostURL.length() == 0) return;
        URL url;
        URLConnection urlConn;
        DataOutputStream printout;
        BufferedReader input;
        url = new URL(solrHostURL);
        urlConn = url.openConnection();
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setUseCaches(false);
        urlConn.setRequestProperty("Content-Type", "text/xml");
        urlConn.setRequestProperty("charset", "utf-8");
        printout = new DataOutputStream(urlConn.getOutputStream());
        String content = "<commit/>";
        printout.writeBytes(content);
        printout.flush();
        printout.close();
        input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
        String str;
        while (null != ((str = input.readLine()))) {
            if (verbose) System.out.println(str); else logger.info(str);
        }
        input.close();
    }
protected int sendData(String submitName, String submitValue) throws HttpException, IOException, SAXException {
        PostMethod postMethod = null;
        try {
            postMethod = new PostMethod(getDocumentBase().toString());
            postMethod.getParams().setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.IGNORE_COOKIES);
            postMethod.addRequestHeader("Cookie", getWikiPrefix() + "_session=" + getSession() + "; " + getWikiPrefix() + "UserID=" + getUserId() + "; " + getWikiPrefix() + "UserName=" + getUserName() + "; ");
            List<Part> parts = new ArrayList<Part>();
            for (String s : new String[] { "wpSection", "wpEdittime", "wpScrolltop", "wpStarttime", "wpEditToken" }) {
                parts.add(new StringPart(s, StringEscapeUtils.unescapeJava(getNonNullParameter(s))));
            }
            parts.add(new StringPart("action", "edit"));
            parts.add(new StringPart("wpTextbox1", getArticleContent()));
            parts.add(new StringPart("wpSummary", getSummary()));
            parts.add(new StringPart("wpAutoSummary", Digest.MD5.isImplemented() ? Digest.MD5.encrypt(getSummary()) : ""));
            parts.add(new StringPart(submitName, submitValue));
            MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), postMethod.getParams());
            postMethod.setRequestEntity(requestEntity);
            int status = getHttpClient().executeMethod(postMethod);
            IOUtils.copyTo(postMethod.getResponseBodyAsStream(), System.err);
            return status;
        } catch (HttpException err) {
            throw err;
        } catch (IOException err) {
            throw err;
        } finally {
            if (postMethod != null) postMethod.releaseConnection();
        }
    }
public Integer execute(Connection con) throws SQLException {
                int updateCount = 0;
                boolean oldAutoCommitSetting = con.getAutoCommit();
                Statement stmt = null;
                try {
                    con.setAutoCommit(autoCommit);
                    stmt = con.createStatement();
                    int statementCount = 0;
                    for (String statement : sql) {
                        try {
                            updateCount += stmt.executeUpdate(statement);
                            statementCount++;
                            if (statementCount % commitRate == 0 && !autoCommit) {
                                con.commit();
                            }
                        } catch (SQLException ex) {
                            if (!failOnError) {
                                log.log(LogLevel.WARN, "%s.  Failed to execute: %s.", ex.getMessage(), sql);
                            } else {
                                throw translate(statement, ex);
                            }
                        }
                    }
                    if (!autoCommit) {
                        con.commit();
                    }
                    return updateCount;
                } catch (SQLException ex) {
                    if (!autoCommit) {
                        con.rollback();
                    }
                    throw ex;
                } finally {
                    close(stmt);
                    con.setAutoCommit(oldAutoCommitSetting);
                }
            }
public Leilao insertLeilao(Leilao leilao) throws SQLException {
        Connection conn = null;
        String insert = "insert into Leilao (idleilao, atividade_idatividade, datainicio, datafim) " + "values " + "(nextval('seq_leilao'), " + leilao.getAtividade().getIdAtividade() + ", '" + leilao.getDataInicio() + "', '" + leilao.getDataFim() + "')";
        try {
            conn = connectionFactory.getConnection(true);
            conn.setAutoCommit(false);
            Statement stmt = conn.createStatement();
            Integer result = stmt.executeUpdate(insert);
            if (result == 1) {
                String sqlSelect = "select last_value from seq_leilao";
                ResultSet rs = stmt.executeQuery(sqlSelect);
                while (rs.next()) {
                    leilao.setIdLeilao(rs.getInt("last_value"));
                }
            }
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            conn.close();
        }
        return null;
    }
public static void copyFile(File sourceFile, File targetFile) throws IOException {
        FileInputStream iStream = new FileInputStream(sourceFile);
        FileOutputStream oStream = new FileOutputStream(targetFile);
        FileChannel inChannel = iStream.getChannel();
        FileChannel outChannel = oStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (true) {
            buffer.clear();
            int readCount = inChannel.read(buffer);
            if (readCount == -1) {
                break;
            }
            buffer.flip();
            outChannel.write(buffer);
        }
        iStream.close();
        oStream.close();
    }
@Test
    public void testDoGet() throws Exception {
        HttpHost targetHost = new HttpHost("localhost", 8080, "http");
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("vince", "test56"));
        try {
            HttpGet httpget = new HttpGet("http://localhost:8080/objectwiz/api?invokeFacetOperation=createNewEntity&objectClassName=org.objectwiz.testapp.jee5.addressbook.Person&applicationName=addressbook&methodReference=persist(E)&args=(lastname=toto)");
            System.out.println("executing request " + httpget.getURI());
            HttpResponse response = client.execute(httpget);
            HttpEntity entity = response.getEntity();
            Header[] headers = response.getAllHeaders();
            for (int i = 0; i < headers.length; i++) {
                Header h = headers[i];
                System.out.println(h.getName() + "/" + h.getValue());
            }
            assertEquals(response.getStatusLine().getStatusCode(), 200);
            System.out.println("----------------------------------------");
            if (entity != null) {
                System.out.println("response content length" + entity.getContentLength());
                System.out.println(entity.getContentType().getName() + "/" + entity.getContentType().getValue());
            }
            httpget.abort();
        } finally {
            client.getConnectionManager().shutdown();
        }
    }
public void parse() throws ParserConfigurationException, SAXException, IOException {
        DefaultHttpClient httpclient = initialise();
        HttpResponse result = httpclient.execute(new HttpGet(urlString));
        SAXParserFactory spf = SAXParserFactory.newInstance();
        if (spf != null) {
            SAXParser sp = spf.newSAXParser();
            sp.parse(result.getEntity().getContent(), this);
        }
    }
private static void zip(ZipArchiveOutputStream zos, File efile, String base) throws IOException {
        if (efile.isDirectory()) {
            File[] lf = efile.listFiles();
            base = base + File.separator + efile.getName();
            for (File file : lf) {
                zip(zos, file, base);
            }
        } else {
            ZipArchiveEntry entry = new ZipArchiveEntry(efile, base + File.separator + efile.getName());
            zos.setEncoding("utf-8");
            zos.putArchiveEntry(entry);
            InputStream is = new FileInputStream(efile);
            IOUtils.copy(is, zos);
            is.close();
            zos.closeArchiveEntry();
        }
    }
@SuppressWarnings("unchecked")
    public static void unzip(String zipFileName, String folder, boolean isCreate) throws IOException {
        File file = new File(zipFileName);
        File folderfile = null;
        if (file.exists() && file.isFile()) {
            String mfolder = folder == null ? file.getParent() : folder;
            String fn = file.getName();
            fn = fn.substring(0, fn.lastIndexOf("."));
            mfolder = isCreate ? (mfolder + File.separator + fn) : mfolder;
            folderfile = new File(mfolder);
            if (!folderfile.exists()) {
                folderfile.mkdirs();
            }
        } else {
            throw new FileNotFoundException("不存在 zip 文件");
        }
        ZipFile zipFile = new ZipFile(file);
        try {
            Enumeration<ZipArchiveEntry> en = zipFile.getEntries();
            ZipArchiveEntry ze = null;
            while (en.hasMoreElements()) {
                ze = en.nextElement();
                if (ze.isDirectory()) {
                    String dirName = ze.getName();
                    dirName = dirName.substring(0, dirName.length() - 1);
                    File f = new File(folderfile.getPath() + File.separator + dirName);
                    f.mkdirs();
                } else {
                    File f = new File(folderfile.getPath() + File.separator + ze.getName());
                    if (!f.getParentFile().exists()) {
                        f.getParentFile().mkdirs();
                    }
                    f.createNewFile();
                    InputStream in = zipFile.getInputStream(ze);
                    OutputStream out = new FileOutputStream(f);
                    IOUtils.copy(in, out);
                    out.close();
                    in.close();
                }
            }
        } finally {
            zipFile.close();
        }
    }
public HttpResponse execute() throws IOException {
            return new HttpResponse() {

                @Override
                public int getResponseCode() throws IOException {
                    return conn.getResponseCode();
                }

                @Override
                public InputStream getContentStream() throws IOException {
                    InputStream errStream = conn.getErrorStream();
                    if (errStream != null) return errStream; else return conn.getInputStream();
                }
            };
        }