semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public ViewedCandidates postViewedCandidates(ViewedCandidates viewedCandidates) throws BookKeeprCommunicationException {
        try {
            synchronized (httpClient) {
                HttpPost req = new HttpPost(remoteHost.getUrl() + "/cand/viewed");
                req.setHeader("Accept-Encoding", "gzip");
                ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
                XMLWriter.write(out, viewedCandidates);
                ByteArrayInputStream in2 = new ByteArrayInputStream(out.toByteArray());
                req.setEntity(new InputStreamEntity(in2, -1));
                HttpResponse resp = httpClient.execute(req);
                if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    try {
                        InputStream in = resp.getEntity().getContent();
                        Header hdr = resp.getFirstHeader("Content-Encoding");
                        String enc = "";
                        if (hdr != null) {
                            enc = resp.getFirstHeader("Content-Encoding").getValue();
                        }
                        if (enc.equals("gzip")) {
                            in = new GZIPInputStream(in);
                        }
                        XMLAble xmlable = XMLReader.read(in);
                        in.close();
                        if (xmlable instanceof ViewedCandidates) {
                            ViewedCandidates p = (ViewedCandidates) xmlable;
                            return p;
                        } else {
                            resp.getEntity().consumeContent();
                            throw new BookKeeprCommunicationException("BookKeepr returned the wrong thing for ViewedCandidates");
                        }
                    } catch (SAXException ex) {
                        Logger.getLogger(BookKeeprConnection.class.getName()).log(Level.WARNING, "Got a malformed message from the bookkeepr", ex);
                        throw new BookKeeprCommunicationException(ex);
                    }
                } else {
                    throw new BookKeeprCommunicationException("Got a " + resp.getStatusLine().getStatusCode() + " from the BookKeepr");
                }
            }
        } catch (HttpException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (IOException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (URISyntaxException ex) {
            throw new BookKeeprCommunicationException(ex);
        }
    }
public Processing getProcess(long processId) throws BookKeeprCommunicationException {
        try {
            synchronized (httpClient) {
                HttpGet req = new HttpGet(remoteHost.getUrl() + "/id/" + Long.toHexString(processId));
                HttpResponse resp = httpClient.execute(req);
                if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    try {
                        XMLAble xmlable = XMLReader.read(resp.getEntity().getContent());
                        if (xmlable instanceof Processing) {
                            Processing p = (Processing) xmlable;
                            return p;
                        } else {
                            throw new BookKeeprCommunicationException("BookKeepr returned the wrong thing for pointingID");
                        }
                    } catch (SAXException ex) {
                        Logger.getLogger(BookKeeprConnection.class.getName()).log(Level.WARNING, "Got a malformed message from the bookkeepr", ex);
                        throw new BookKeeprCommunicationException(ex);
                    }
                } else {
                    resp.getEntity().consumeContent();
                    throw new BookKeeprCommunicationException("Got a " + resp.getStatusLine().getStatusCode() + " from the BookKeepr");
                }
            }
        } catch (HttpException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (IOException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (URISyntaxException ex) {
            throw new BookKeeprCommunicationException(ex);
        }
    }
public RawCandidate getRawCandidate(long candId) throws BookKeeprCommunicationException {
        try {
            synchronized (httpClient) {
                HttpGet req = new HttpGet(remoteHost.getUrl() + "/cand/" + Long.toHexString(candId));
                req.setHeader("Accept-Encoding", "gzip");
                HttpResponse resp = httpClient.execute(req);
                if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    try {
                        InputStream in = resp.getEntity().getContent();
                        Header hdr = resp.getFirstHeader("Content-Encoding");
                        String enc = "";
                        if (hdr != null) {
                            enc = resp.getFirstHeader("Content-Encoding").getValue();
                        }
                        if (enc.equals("gzip")) {
                            in = new GZIPInputStream(in);
                        }
                        XMLAble xmlable = XMLReader.read(in);
                        in.close();
                        if (xmlable instanceof RawCandidate) {
                            RawCandidate p = (RawCandidate) xmlable;
                            return p;
                        } else {
                            throw new BookKeeprCommunicationException("BookKeepr returned the wrong thing for candId");
                        }
                    } catch (SAXException ex) {
                        Logger.getLogger(BookKeeprConnection.class.getName()).log(Level.WARNING, "Got a malformed message from the bookkeepr", ex);
                        throw new BookKeeprCommunicationException(ex);
                    }
                } else {
                    resp.getEntity().consumeContent();
                    throw new BookKeeprCommunicationException("Got a " + resp.getStatusLine().getStatusCode() + " from the BookKeepr");
                }
            }
        } catch (HttpException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (IOException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (URISyntaxException ex) {
            throw new BookKeeprCommunicationException(ex);
        }
    }
public List<CandidateListStub> getAllCandLists() throws BookKeeprCommunicationException {
        try {
            synchronized (httpClient) {
                HttpGet req = new HttpGet(remoteHost.getUrl() + "/cand/lists");
                HttpResponse resp = httpClient.execute(req);
                if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    try {
                        InputStream in = resp.getEntity().getContent();
                        XMLAble xmlable = XMLReader.read(in);
                        in.close();
                        if (xmlable instanceof CandidateListIndex) {
                            CandidateListIndex idx = (CandidateListIndex) xmlable;
                            return idx.getCandidateListStubList();
                        } else {
                            throw new BookKeeprCommunicationException("BookKeepr returned the wrong thing for /cand/lists");
                        }
                    } catch (SAXException ex) {
                        Logger.getLogger(BookKeeprConnection.class.getName()).log(Level.WARNING, "Got a malformed message from the bookkeepr", ex);
                        throw new BookKeeprCommunicationException(ex);
                    }
                } else {
                    resp.getEntity().consumeContent();
                    throw new BookKeeprCommunicationException("Got a " + resp.getStatusLine().getStatusCode() + " from the BookKeepr");
                }
            }
        } catch (HttpException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (IOException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (URISyntaxException ex) {
            throw new BookKeeprCommunicationException(ex);
        }
    }
public Psrxml getPsrxmlForCandidateList(CandidateList clist) throws BookKeeprCommunicationException {
        try {
            synchronized (httpClient) {
                long psrxmlid = clist.getPsrxmlId();
                HttpGet req = new HttpGet(remoteHost.getUrl() + "/id/" + StringConvertable.ID.toString(psrxmlid));
                HttpResponse resp = httpClient.execute(req);
                if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    try {
                        InputStream in = resp.getEntity().getContent();
                        XMLAble xmlable = XMLReader.read(in);
                        in.close();
                        if (xmlable instanceof Psrxml) {
                            Psrxml psrxml = (Psrxml) xmlable;
                            return psrxml;
                        } else {
                            throw new BookKeeprCommunicationException("BookKeepr returned the wrong thing for psrxml id " + psrxmlid);
                        }
                    } catch (SAXException ex) {
                        Logger.getLogger(BookKeeprConnection.class.getName()).log(Level.WARNING, "Got a malformed message from the bookkeepr", ex);
                        throw new BookKeeprCommunicationException(ex);
                    }
                } else {
                    resp.getEntity().consumeContent();
                    throw new BookKeeprCommunicationException("Got a " + resp.getStatusLine().getStatusCode() + " from the BookKeepr  (" + remoteHost.getUrl() + "/id/" + StringConvertable.ID + ")");
                }
            }
        } catch (HttpException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (IOException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (URISyntaxException ex) {
            throw new BookKeeprCommunicationException(ex);
        }
    }
public int process(ProcessorContext context) throws InterruptedException, ProcessorException {
        logger.info("JAISaveTask:process");
        final RenderedOp im = (RenderedOp) context.get("RenderedOp");
        final String path = "s3://s3.amazonaws.com/rssfetch/" + (new Guid());
        final PNGEncodeParam.RGB encPar = new PNGEncodeParam.RGB();
        encPar.setTransparentRGB(new int[] { 0, 0, 0 });
        File tmpFile = null;
        try {
            tmpFile = File.createTempFile("thmb", ".png");
            OutputStream out = new FileOutputStream(tmpFile);
            final ParameterBlock pb = (new ParameterBlock()).addSource(im).add(out).add("png").add(encPar);
            JAI.create("encode", pb, null);
            out.flush();
            out.close();
            FileInputStream in = new FileInputStream(tmpFile);
            final XFile xfile = new XFile(path);
            final XFileOutputStream xout = new XFileOutputStream(xfile);
            final com.luzan.common.nfs.s3.XFileExtensionAccessor xfa = ((com.luzan.common.nfs.s3.XFileExtensionAccessor) xfile.getExtensionAccessor());
            if (xfa != null) {
                xfa.setMimeType("image/png");
                xfa.setContentLength(tmpFile.length());
            }
            IOUtils.copy(in, xout);
            xout.flush();
            xout.close();
            in.close();
            context.put("outputPath", path);
        } catch (IOException e) {
            logger.error(e);
            throw new ProcessorException(e);
        } catch (Throwable e) {
            logger.error(e);
            throw new ProcessorException(e);
        } finally {
            if (tmpFile != null && tmpFile.exists()) {
                tmpFile.delete();
            }
        }
        return TaskState.STATE_MO_START + TaskState.STATE_ENCODE;
    }
public void updateCoordinates(Address address) {
        String mapURL = "http://maps.google.com/maps/geo?output=csv";
        String mapKey = "ABQIAAAAi__aT6y6l86JjbootR-p9xQd1nlEHNeAVGWQhS84yIVN5yGO2RQQPg9QLzy82PFlCzXtMNe6ofKjnA";
        String location = address.getStreet() + " " + address.getZip() + " " + address.getCity();
        if (logger.isDebugEnabled()) {
            logger.debug(location);
        }
        double[] coordinates = { 0.0, 0.0 };
        String content = "";
        try {
            location = URLEncoder.encode(location, "UTF-8");
            String request = mapURL + "&q=" + location + "&key=" + mapKey;
            URL url = new URL(request);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                content += line;
            }
            reader.close();
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Error from google: " + e.getMessage());
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug(content);
        }
        StringTokenizer tokenizer = new StringTokenizer(content, ",");
        int i = 0;
        while (tokenizer.hasMoreTokens()) {
            i++;
            String token = tokenizer.nextToken();
            if (i == 3) {
                coordinates[0] = Double.parseDouble(token);
            }
            if (i == 4) {
                coordinates[1] = Double.parseDouble(token);
            }
        }
        if ((coordinates[0] != 0) || (coordinates[1] != 0)) {
            address.setLatitude(coordinates[0]);
            address.setLongitude(coordinates[1]);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Invalid coordinates for address " + address.getId());
            }
        }
    }
public static boolean copyFile(File outFile, File inFile) {
        InputStream inStream = null;
        OutputStream outStream = null;
        try {
            if (outFile.createNewFile()) {
                inStream = new FileInputStream(inFile);
                outStream = new FileOutputStream(outFile);
                byte[] buffer = new byte[1024];
                int length;
                while ((length = inStream.read(buffer)) > 0) outStream.write(buffer, 0, length);
                inStream.close();
                outStream.close();
            } else return false;
        } catch (IOException iox) {
            iox.printStackTrace();
            return false;
        }
        return true;
    }
public IContentExtension[] getContentExtensions(String locale) {
        if (RemoteHelp.isEnabled()) {
            List contributions = new ArrayList();
            PreferenceFileHandler handler = new PreferenceFileHandler();
            String isEnabled[] = handler.isEnabled();
            for (int ic = 0; ic < handler.getTotalRemoteInfocenters(); ic++) {
                if (isEnabled[ic].equalsIgnoreCase("true")) {
                    InputStream in = null;
                    try {
                        URL url = RemoteHelp.getURL(ic, PATH_EXTENSIONS);
                        in = url.openStream();
                        if (reader == null) {
                            reader = new DocumentReader();
                        }
                        UAElement element = reader.read(in);
                        IContentExtension[] children = (IContentExtension[]) element.getChildren(IContentExtension.class);
                        for (int contrib = 0; contrib < children.length; contrib++) {
                            contributions.add(children[contrib]);
                        }
                    } catch (IOException e) {
                        String msg = "I/O error while trying to contact the remote help server";
                        HelpBasePlugin.logError(msg, e);
                    } catch (Throwable t) {
                        String msg = "Internal error while reading topic extensions from remote server";
                        HelpBasePlugin.logError(msg, t);
                    } finally {
                        if (in != null) {
                            try {
                                in.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                }
            }
            return (IContentExtension[]) contributions.toArray(new IContentExtension[contributions.size()]);
        }
        return new IContentExtension[0];
    }
public void putChunk(String chunk) throws JacsonException {
        try {
            URL url = new URL(chunk);
            InputStream is = url.openStream();
            if (inverse) drain.putChunk(chunk);
            is.close();
        } catch (IOException broken) {
            if (!inverse) drain.putChunk(chunk);
        }
    }
private static void copy(File source, File target) throws IOException {
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(source);
            to = new FileOutputStream(target);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
            }
        }
    }
@SuppressWarnings("unchecked")
    public static synchronized MetaDataBean getMetaDataByUrl(URL url) {
        if (url == null) throw new IllegalArgumentException("Properties url for meta data is null");
        MetaDataBean mdb = metaDataByUrl.get(url);
        if (mdb != null) return mdb;
        log.info("Loading metadata " + url);
        Properties properties = new Properties();
        try {
            properties.load(url.openStream());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        mdb = new MetaDataBean((Map) properties);
        metaDataByUrl.put(url, mdb);
        mdb.instanceValue = url.toString();
        return mdb;
    }
private Face(String font) throws IOException {
        characterWidths = new double[256];
        StringBuffer sb = new StringBuffer();
        sb.append('/');
        sb.append(Constants.FONTS_DIR);
        sb.append('/');
        sb.append(font);
        sb.append(Constants.CHAR_WIDTHS_SUFFIX);
        String path = sb.toString();
        URL url = getClass().getResource(path);
        InputStream is = url.openStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        int pos = 0;
        String width = br.readLine();
        while (width != null && pos < 256) {
            characterWidths[pos] = Double.parseDouble(width);
            pos++;
            width = br.readLine();
        }
    }
public static String hash(String plainTextPwd) {
        MessageDigest hashAlgo;
        try {
            hashAlgo = java.security.MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new QwickException(e);
        }
        hashAlgo.update(plainTextPwd.getBytes());
        return new String(hashAlgo.digest());
    }
private void copyFile(String fileName, String messageID, boolean isError) {
        try {
            File inputFile = new File(fileName);
            File outputFile = null;
            if (isError) {
                outputFile = new File(provider.getErrorDataLocation(folderName) + messageID + ".xml");
            } else {
                outputFile = new File(provider.getDataProcessedLocation(folderName) + messageID + ".xml");
            }
            FileReader in = new FileReader(inputFile);
            FileWriter out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (Exception e) {
        }
    }
public static void copyFile(File input, File output) throws Exception {
        FileReader in = new FileReader(input);
        FileWriter out = new FileWriter(output);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
    }
private static void downloadFile(URL url, File destFile) throws Exception {
        try {
            URLConnection urlConnection = url.openConnection();
            File tmpFile = null;
            try {
                tmpFile = File.createTempFile("remoteLib_", null);
                InputStream in = null;
                FileOutputStream out = null;
                try {
                    in = urlConnection.getInputStream();
                    out = new FileOutputStream(tmpFile);
                    IOUtils.copy(in, out);
                } finally {
                    if (out != null) {
                        out.close();
                    }
                    if (in != null) {
                        in.close();
                    }
                }
                FileUtils.copyFile(tmpFile, destFile);
            } finally {
                if (tmpFile != null) {
                    tmpFile.delete();
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException("Could not download URL: " + url, ex);
        }
    }
public void readPersistentProperties() {
        try {
            String file = System.getProperty("user.home") + System.getProperty("file.separator") + ".das2rc";
            File f = new File(file);
            if (f.canRead()) {
                try {
                    InputStream in = new FileInputStream(f);
                    load(in);
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    org.das2.util.DasExceptionHandler.handle(e);
                }
            } else {
                if (!f.exists() && f.canWrite()) {
                    try {
                        OutputStream out = new FileOutputStream(f);
                        store(out, "");
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                        org.das2.util.DasExceptionHandler.handle(e);
                    }
                } else {
                    System.err.println("Unable to read or write " + file + ".  Using defaults.");
                }
            }
        } catch (SecurityException ex) {
            ex.printStackTrace();
        }
    }
public static String read(URL url) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        StringWriter res = new StringWriter();
        PrintWriter writer = new PrintWriter(new BufferedWriter(res));
        String line;
        while ((line = reader.readLine()) != null) {
            writer.println(line);
        }
        reader.close();
        writer.close();
        return res.toString();
    }
protected InputStream getAudioStream() {
        InputStream in = null;
        try {
            URL url = getAudioURL();
            if (url != null) in = url.openStream();
        } catch (IOException ex) {
            System.err.println(ex);
        }
        return in;
    }
public static String fetch(String reference) throws IOException {
        URL url = new URL(reference);
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
        return parseISToString(c.getInputStream());
    }
public static String generateDigest(String message, String DigestAlgorithm) {
        try {
            MessageDigest md = MessageDigest.getInstance(DigestAlgorithm);
            md.update(message.getBytes(), 0, message.length());
            return new BigInteger(1, md.digest()).toString(16);
        } catch (NoSuchAlgorithmException nsae) {
            return null;
        }
    }