semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void copyFile(String input, String output) {
        try {
            FileChannel srcChannel = new FileInputStream("srcFilename").getChannel();
            FileChannel dstChannel = new FileOutputStream("dstFilename").getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (IOException e) {
        }
    }
public Element rootFromURL(URL url) throws org.jdom.JDOMException, java.io.IOException {
        Element e;
        try {
            InputStream stream = new BufferedInputStream(url.openConnection().getInputStream());
            return getRootViaURI(verify, stream);
        } catch (org.jdom.input.JDOMParseException e4) {
            throw e4;
        } catch (org.jdom.JDOMException e1) {
            if (!openWarn1) reportError1(url.toString(), e1);
            openWarn1 = true;
            try {
                InputStream stream = new BufferedInputStream(url.openConnection().getInputStream());
                e = getRootViaURL(verify, stream);
                log.info("getRootViaURL succeeded as 2nd try");
                return e;
            } catch (org.jdom.JDOMException e2) {
                if (!openWarn2) reportError2(url.toString(), e2);
                openWarn2 = true;
                InputStream stream = new BufferedInputStream(url.openConnection().getInputStream());
                e = getRootViaRelative(verify, stream);
                log.info("GetRootViaRelative succeeded as 3rd try");
                new Exception().printStackTrace();
                return e;
            }
        }
    }
public static void copyFile(File from, File to) {
            try {
                FileInputStream in = new FileInputStream(from);
                FileOutputStream out = new FileOutputStream(to);
                byte[] buffer = new byte[1024 * 16];
                int read = 0;
                while ((read = in.read(buffer)) >= 0) {
                    out.write(buffer, 0, read);
                }
                in.close();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
public Service findServiceFor(final int serviceID) throws JAXBException, IOException, BadResponseException {
        final String USER_AGENT = "SBSIVisual (CSBE, University of Edinburgh)";
        String urlToConnectTo = "http://www.biocatalogue.org/services/" + serviceID;
        URL url = new URL(urlToConnectTo);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("User-Agent", USER_AGENT);
        conn.setRequestProperty("Accept", "application/xml");
        int iResponseCode = conn.getResponseCode();
        InputStream serverResponse = null;
        switch(iResponseCode) {
            case HttpURLConnection.HTTP_OK:
                serverResponse = conn.getInputStream();
                break;
            case HttpURLConnection.HTTP_BAD_REQUEST:
                throw new BadResponseException("Received BadResponse from server:" + HttpURLConnection.HTTP_BAD_REQUEST);
        }
        Service service = new ResponseParser<Service>().getObjectFor(serverResponse, Service.class);
        return service;
    }
public static String doPostEntity(String URL, List<NameValuePair> params) {
        try {
            OauthUtil util = new OauthUtil();
            URI uri = new URI(URL);
            HttpClient httpclient = util.getNewHttpClient();
            HttpPost postMethod = new HttpPost(uri);
            postMethod.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
            HttpResponse httpResponse = httpclient.execute(postMethod);
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                String strResult = EntityUtils.toString(httpResponse.getEntity());
                Log.i("DEBUG", "result: " + strResult);
                String token;
                try {
                    JSONObject obj = new JSONObject(strResult);
                    token = obj.getString("access_token");
                } catch (Exception e) {
                    token = strResult.substring(strResult.indexOf("access_token=") + 13);
                }
                return token;
            }
        } catch (Exception e) {
            Log.i("DEBUG", e.toString());
        }
        return null;
    }
public static String doPost(String URL, List<NameValuePair> params) {
        try {
            OauthUtil util = new OauthUtil();
            URI uri = new URI(URL);
            HttpClient httpclient = util.getNewHttpClient();
            HttpPost postMethod = new HttpPost(uri);
            StringBuffer paramString = new StringBuffer();
            paramString.append("OAuth");
            for (int i = 0; i < params.size(); i++) {
                paramString.append(" " + params.get(i).getName());
                paramString.append("=\"" + encodeUrl(params.get(i).getValue()) + "\",");
            }
            String xx = paramString.substring(0, paramString.length() - 1);
            postMethod.addHeader("Authorization", xx);
            HttpResponse httpResponse = httpclient.execute(postMethod);
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                String strResult = EntityUtils.toString(httpResponse.getEntity());
                Log.i("DEBUG", "result: " + strResult);
                return strResult;
            }
        } catch (Exception e) {
            Log.i("DEBUG", e.toString());
        }
        return null;
    }
public static String generateNonce(boolean is32) {
        Random random = new Random();
        String result = String.valueOf(random.nextInt(9876599) + 123400);
        if (is32) {
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(result.getBytes());
                byte b[] = md.digest();
                int i;
                StringBuffer buf = new StringBuffer("");
                for (int offset = 0; offset < b.length; offset++) {
                    i = b[offset];
                    if (i < 0) i += 256;
                    if (i < 16) buf.append("0");
                    buf.append(Integer.toHexString(i));
                }
                result = buf.toString();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
public static void copyFile(File in, File out) throws IOException {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        sourceChannel.close();
        destinationChannel.close();
    }
public static String hashValue(String password, String salt) throws TeqloException {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
            md.update(password.getBytes("UTF-8"));
            md.update(salt.getBytes("UTF-8"));
            byte raw[] = md.digest();
            char[] encoded = (new BASE64Encoder()).encode(raw).toCharArray();
            int length = encoded.length;
            while (length > 0 && encoded[length - 1] == '=') length--;
            for (int i = 0; i < length; i++) {
                if (encoded[i] == '+') encoded[i] = '*'; else if (encoded[i] == '/') encoded[i] = '-';
            }
            return new String(encoded, 0, length);
        } catch (Exception e) {
            throw new TeqloException("Security", "password", e, "Could not process password");
        }
    }
private void serviceResource(HttpServletRequest request, HttpServletResponse response, ServletConfig config) throws IOException {
        String uri = (String) request.getAttribute("javax.servlet.include.request_uri");
        if (uri == null) uri = request.getRequestURI();
        if (uri.endsWith(".shtml")) {
            serviceSSIResource(uri, response, config);
        } else {
            String target = uri.substring(servletPath.length());
            ServletContext context = config.getServletContext();
            URL url = context.getResource(target);
            URLConnection resource = url.openConnection();
            String contentType = context.getMimeType(uri);
            if (contentType == null) contentType = resource.getContentType();
            if (contentType != null) {
                String encoding = resource.getContentEncoding();
                if (encoding != null) contentType += "; charset=" + encoding;
                response.setContentType(contentType);
            }
            int contentLength = resource.getContentLength();
            if (contentLength > 0) response.setContentLength(contentLength);
            InputStream is = resource.getInputStream();
            OutputStream os = response.getOutputStream();
            int bytesRead = 0;
            byte buffer[] = new byte[512];
            while ((bytesRead = is.read(buffer)) != -1) os.write(buffer, 0, bytesRead);
            is.close();
        }
    }
private static String extractFirstLine(String urlToFile) {
        try {
            URL url = new URL(urlToFile);
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            return br.readLine();
        } catch (Exception e) {
            return null;
        }
    }
public static void checkAndUpdateGameData() {
        new ErrThread() {

            @Override
            public void handledRun() throws Throwable {
                try {
                    URL url = new URL(ONLINE_CLIENT_DATA + "gamedata.xml");
                    BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
                    int lastversion = 0;
                    String readHeader1 = br.readLine();
                    String readHeader2 = br.readLine();
                    String[] parts = readHeader2.split(" ");
                    lastversion = new Integer(parts[1]);
                    GameDatabase.loadVersion();
                    if (GameDatabase.version < lastversion) {
                        Logger.log(LogTypes.LOG, "Downloading new gamedata");
                        BufferedOutputStream bo = null;
                        File destfile = new File(GameDatabase.dataFilePath);
                        if (!destfile.createNewFile()) {
                            destfile.delete();
                            destfile.createNewFile();
                        }
                        bo = new BufferedOutputStream(new FileOutputStream(destfile));
                        bo.write((readHeader1 + "\n").getBytes());
                        bo.write((readHeader2 + "\n").getBytes());
                        int readedbyte;
                        while ((readedbyte = br.read()) != -1) {
                            bo.write(readedbyte);
                        }
                        bo.flush();
                        try {
                            br.close();
                            bo.close();
                        } catch (Exception ex) {
                            Logger.log(ex);
                        }
                    }
                } catch (java.net.UnknownHostException unknownHost) {
                    Logger.log("Sourceforge is down, cannot update gamedata");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(FrameOrganizer.getClientFrame(), "The gamedata is outdated, but Coopnet couldn't update it!", "Gamedata outdated", JOptionPane.INFORMATION_MESSAGE);
                    throw e;
                } finally {
                    GameDatabase.loadVersion();
                    GameDatabase.load("", GameDatabase.dataFilePath);
                    GameDatabase.detectGames();
                }
            }
        }.start();
    }
@Override
            public void handledRun() throws Throwable {
                try {
                    URL url = new URL(ONLINE_CLIENT_DATA + "gamedata.xml");
                    BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
                    int lastversion = 0;
                    String readHeader1 = br.readLine();
                    String readHeader2 = br.readLine();
                    String[] parts = readHeader2.split(" ");
                    lastversion = new Integer(parts[1]);
                    GameDatabase.loadVersion();
                    if (GameDatabase.version < lastversion) {
                        Logger.log(LogTypes.LOG, "Downloading new gamedata");
                        BufferedOutputStream bo = null;
                        File destfile = new File(GameDatabase.dataFilePath);
                        if (!destfile.createNewFile()) {
                            destfile.delete();
                            destfile.createNewFile();
                        }
                        bo = new BufferedOutputStream(new FileOutputStream(destfile));
                        bo.write((readHeader1 + "\n").getBytes());
                        bo.write((readHeader2 + "\n").getBytes());
                        int readedbyte;
                        while ((readedbyte = br.read()) != -1) {
                            bo.write(readedbyte);
                        }
                        bo.flush();
                        try {
                            br.close();
                            bo.close();
                        } catch (Exception ex) {
                            Logger.log(ex);
                        }
                    }
                } catch (java.net.UnknownHostException unknownHost) {
                    Logger.log("Sourceforge is down, cannot update gamedata");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(FrameOrganizer.getClientFrame(), "The gamedata is outdated, but Coopnet couldn't update it!", "Gamedata outdated", JOptionPane.INFORMATION_MESSAGE);
                    throw e;
                } finally {
                    GameDatabase.loadVersion();
                    GameDatabase.load("", GameDatabase.dataFilePath);
                    GameDatabase.detectGames();
                }
            }
public Usuario insertUsuario(IUsuario usuario) throws SQLException {
        Connection conn = null;
        String insert = "insert into Usuario (idusuario, nome, email, telefone, cpf, login, senha) " + "values " + "(nextval('seq_usuario'), '" + usuario.getNome() + "', '" + usuario.getEmail() + "', " + "'" + usuario.getTelefone() + "', '" + usuario.getCpf() + "', '" + usuario.getLogin() + "', '" + usuario.getSenha() + "')";
        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_usuario";
                ResultSet rs = stmt.executeQuery(sqlSelect);
                while (rs.next()) {
                    usuario.setIdUsuario(rs.getInt("last_value"));
                }
                if (usuario instanceof Requerente) {
                    RequerenteDAO requerenteDAO = new RequerenteDAO();
                    requerenteDAO.insertRequerente((Requerente) usuario, conn);
                } else if (usuario instanceof RecursoHumano) {
                    RecursoHumanoDAO recursoHumanoDAO = new RecursoHumanoDAO();
                    recursoHumanoDAO.insertRecursoHumano((RecursoHumano) usuario, conn);
                }
            }
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            conn.close();
        }
        return null;
    }
private HttpURLConnection getHttpURLConnection(String bizDocToExecute) {
        StringBuffer servletURL = new StringBuffer();
        servletURL.append(getBaseServletURL());
        servletURL.append("?_BIZVIEW=").append(bizDocToExecute);
        Map<String, Object> inputParms = getInputParams();
        if (inputParms != null) {
            Set<Entry<String, Object>> entrySet = inputParms.entrySet();
            for (Entry<String, Object> entry : entrySet) {
                String name = entry.getKey();
                String value = entry.getValue().toString();
                servletURL.append("&").append(name).append("=").append(value);
            }
        }
        HttpURLConnection connection = null;
        try {
            URL url = new URL(servletURL.toString());
            connection = (HttpURLConnection) url.openConnection();
        } catch (IOException e) {
            Assert.fail("Failed to connect to the test servlet: " + e);
        }
        return connection;
    }
void writeToFile(String dir, InputStream input, String fileName) throws FileNotFoundException, IOException {
        makeDirs(dir);
        FileOutputStream fo = null;
        try {
            System.out.println(Thread.currentThread().getName() + " : " + "Writing file " + fileName + " to path " + dir);
            File file = new File(dir, fileName);
            fo = new FileOutputStream(file);
            IOUtils.copy(input, fo);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Failed to write " + fileName);
        }
    }
@Test
    public void testClient() throws ClientProtocolException, IOException {
        HttpClient httpclient = new DefaultHttpClient();
        HttpHost proxy = new HttpHost("127.0.0.1", 1280, "http");
        HttpGet httpget = new HttpGet("http://a.b.c.d/pdn/");
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        System.out.println("executing request " + httpget.getURI());
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
        }
        InputStream is = response.getEntity().getContent();
        readInputStream(is);
        System.out.println("----------------------------------------");
        httpget.abort();
        httpclient.getConnectionManager().shutdown();
    }
public void testExecute() throws Exception {
        LocalWorker worker = new JTidyWorker();
        URL url = new URL("http://www.nature.com/index.html");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        StringBuffer sb = new StringBuffer();
        while ((str = in.readLine()) != null) {
            sb.append(str);
            sb.append(LINE_ENDING);
        }
        in.close();
        Map inputMap = new HashMap();
        DataThingAdapter inAdapter = new DataThingAdapter(inputMap);
        inAdapter.putString("inputHtml", sb.toString());
        Map outputMap = worker.execute(inputMap);
        DataThingAdapter outAdapter = new DataThingAdapter(outputMap);
        assertNotNull("The outputMap was null", outputMap);
        String results = outAdapter.getString("results");
        assertFalse("The results were empty", results.equals(""));
        assertNotNull("The results were null", results);
    }
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mTextView = (TextView) findViewById(R.id.textView001);
        mButton = (Button) findViewById(R.id.Button001);
        tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        mButton.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
                int cid = gcl.getCid();
                int lac = gcl.getLac();
                int mcc = Integer.valueOf(tm.getNetworkOperator().substring(0, 3));
                int mnc = Integer.valueOf(tm.getNetworkOperator().substring(3, 5));
                try {
                    JSONObject holder = new JSONObject();
                    holder.put("version", "1.1.0");
                    holder.put("host", "maps.google.com");
                    holder.put("request_address", true);
                    JSONArray array = new JSONArray();
                    JSONObject data = new JSONObject();
                    data.put("cell_id", cid);
                    data.put("location_area_code", lac);
                    data.put("mobile_country_code", mcc);
                    data.put("mobile_network_code", mnc);
                    array.put(data);
                    holder.put("cell_towers", array);
                    DefaultHttpClient client = new DefaultHttpClient();
                    HttpPost post = new HttpPost("http://www.google.com/loc/json");
                    StringEntity se = new StringEntity(holder.toString());
                    post.setEntity(se);
                    HttpResponse resp = client.execute(post);
                    HttpEntity entity = resp.getEntity();
                    BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
                    StringBuffer sb = new StringBuffer();
                    String result = br.readLine();
                    while (result != null) {
                        sb.append(result);
                        result = br.readLine();
                    }
                    JSONObject jsonObject = new JSONObject(sb.toString());
                    JSONObject jsonObject1 = new JSONObject(jsonObject.getString("location"));
                    getAddress(jsonObject1.getString("latitude"), jsonObject1.getString("longitude"));
                } catch (Exception e) {
                }
            }
        });
    }
@Override
            public void onClick(View v) {
                GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
                int cid = gcl.getCid();
                int lac = gcl.getLac();
                int mcc = Integer.valueOf(tm.getNetworkOperator().substring(0, 3));
                int mnc = Integer.valueOf(tm.getNetworkOperator().substring(3, 5));
                try {
                    JSONObject holder = new JSONObject();
                    holder.put("version", "1.1.0");
                    holder.put("host", "maps.google.com");
                    holder.put("request_address", true);
                    JSONArray array = new JSONArray();
                    JSONObject data = new JSONObject();
                    data.put("cell_id", cid);
                    data.put("location_area_code", lac);
                    data.put("mobile_country_code", mcc);
                    data.put("mobile_network_code", mnc);
                    array.put(data);
                    holder.put("cell_towers", array);
                    DefaultHttpClient client = new DefaultHttpClient();
                    HttpPost post = new HttpPost("http://www.google.com/loc/json");
                    StringEntity se = new StringEntity(holder.toString());
                    post.setEntity(se);
                    HttpResponse resp = client.execute(post);
                    HttpEntity entity = resp.getEntity();
                    BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
                    StringBuffer sb = new StringBuffer();
                    String result = br.readLine();
                    while (result != null) {
                        sb.append(result);
                        result = br.readLine();
                    }
                    JSONObject jsonObject = new JSONObject(sb.toString());
                    JSONObject jsonObject1 = new JSONObject(jsonObject.getString("location"));
                    getAddress(jsonObject1.getString("latitude"), jsonObject1.getString("longitude"));
                } catch (Exception e) {
                }
            }