semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void write(HttpServletRequest req, HttpServletResponse res, Object bean) throws IntrospectionException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
        res.setContentType(contentType);
        final Object r;
        if (HttpRpcServer.HttpRpcOutput.class.isAssignableFrom(bean.getClass())) {
            HttpRpcServer.HttpRpcOutput output = (HttpRpcServer.HttpRpcOutput) bean;
            r = output.getResult();
        } else r = bean;
        if (r != null) {
            final ServletOutputStream outputStream = res.getOutputStream();
            if (File.class.isAssignableFrom(r.getClass())) {
                File file = (File) r;
                InputStream in = null;
                try {
                    in = new FileInputStream(file);
                    IOUtils.copy(in, outputStream);
                } finally {
                    if (in != null) in.close();
                }
            } else if (InputStream.class.isAssignableFrom(r.getClass())) {
                InputStream in = null;
                try {
                    in = (InputStream) r;
                    if (ByteArrayInputStream.class.isAssignableFrom(r.getClass())) res.addHeader("Content-Length", Integer.toString(in.available()));
                    IOUtils.copy(in, outputStream);
                } finally {
                    if (in != null) in.close();
                }
            }
            outputStream.flush();
        }
    }
public InputSource resolveEntity(String publicId, String systemId) {
        String resolved = getResolvedEntity(publicId, systemId);
        if (resolved != null) {
            try {
                InputSource iSource = new InputSource(resolved);
                iSource.setPublicId(publicId);
                URL url = new URL(resolved);
                InputStream iStream = url.openStream();
                iSource.setByteStream(iStream);
                return iSource;
            } catch (Exception e) {
                catalogManager.debug.message(1, "Failed to create InputSource (" + e.toString() + ")", resolved);
                return null;
            }
        }
        return null;
    }
private void copy(File in, File out) {
        log.info("Copying yam file from: " + in.getName() + " to: " + out.getName());
        try {
            FileChannel ic = new FileInputStream(in).getChannel();
            FileChannel oc = new FileOutputStream(out).getChannel();
            ic.transferTo(0, ic.size(), oc);
            ic.close();
            oc.close();
        } catch (IOException ioe) {
            fail("Failed testing while copying modified file: " + ioe.getMessage());
        }
    }
public static final String md5(final String s) {
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(s.getBytes());
            byte messageDigest[] = digest.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                String h = Integer.toHexString(0xFF & messageDigest[i]);
                while (h.length() < 2) h = "0" + h;
                hexString.append(h);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
        }
        return "";
    }
public void testSimpleBasicHttpRequests() throws Exception {
        int reqNo = 20;
        Random rnd = new Random();
        final List testData = new ArrayList(reqNo);
        for (int i = 0; i < reqNo; i++) {
            int size = rnd.nextInt(5000);
            byte[] data = new byte[size];
            rnd.nextBytes(data);
            testData.add(data);
        }
        this.server.registerHandler("*", new HttpRequestHandler() {

            public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
                String s = request.getRequestLine().getUri();
                if (s.startsWith("/?")) {
                    s = s.substring(2);
                }
                int index = Integer.parseInt(s);
                byte[] data = (byte[]) testData.get(index);
                ByteArrayEntity entity = new ByteArrayEntity(data);
                response.setEntity(entity);
            }
        });
        this.server.start();
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());
        try {
            for (int r = 0; r < reqNo; r++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket, this.client.getParams());
                }
                BasicHttpRequest get = new BasicHttpRequest("GET", "/?" + r);
                HttpResponse response = this.client.execute(get, host, conn);
                byte[] received = EntityUtils.toByteArray(response.getEntity());
                byte[] expected = (byte[]) testData.get(r);
                assertEquals(expected.length, received.length);
                for (int i = 0; i < expected.length; i++) {
                    assertEquals(expected[i], received[i]);
                }
                if (!this.client.keepAlive(response)) {
                    conn.close();
                }
            }
            HttpConnectionMetrics cm = conn.getMetrics();
            assertEquals(reqNo, cm.getRequestCount());
            assertEquals(reqNo, cm.getResponseCount());
        } finally {
            conn.close();
            this.server.shutdown();
        }
    }
public void testSimpleHttpPostsWithContentLength() throws Exception {
        int reqNo = 20;
        Random rnd = new Random();
        List testData = new ArrayList(reqNo);
        for (int i = 0; i < reqNo; i++) {
            int size = rnd.nextInt(5000);
            byte[] data = new byte[size];
            rnd.nextBytes(data);
            testData.add(data);
        }
        this.server.registerHandler("*", new HttpRequestHandler() {

            public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] data = EntityUtils.toByteArray(incoming);
                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
                    outgoing.setChunked(false);
                    response.setEntity(outgoing);
                } else {
                    StringEntity outgoing = new StringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        });
        this.server.start();
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());
        try {
            for (int r = 0; r < reqNo; r++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket, this.client.getParams());
                }
                BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
                byte[] data = (byte[]) testData.get(r);
                ByteArrayEntity outgoing = new ByteArrayEntity(data);
                post.setEntity(outgoing);
                HttpResponse response = this.client.execute(post, host, conn);
                byte[] received = EntityUtils.toByteArray(response.getEntity());
                byte[] expected = (byte[]) testData.get(r);
                assertEquals(expected.length, received.length);
                for (int i = 0; i < expected.length; i++) {
                    assertEquals(expected[i], received[i]);
                }
                if (!this.client.keepAlive(response)) {
                    conn.close();
                }
            }
            HttpConnectionMetrics cm = conn.getMetrics();
            assertEquals(reqNo, cm.getRequestCount());
            assertEquals(reqNo, cm.getResponseCount());
        } finally {
            conn.close();
            this.server.shutdown();
        }
    }
public void testSimpleHttpPostsChunked() throws Exception {
        int reqNo = 20;
        Random rnd = new Random();
        List testData = new ArrayList(reqNo);
        for (int i = 0; i < reqNo; i++) {
            int size = rnd.nextInt(20000);
            byte[] data = new byte[size];
            rnd.nextBytes(data);
            testData.add(data);
        }
        this.server.registerHandler("*", new HttpRequestHandler() {

            public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] data = EntityUtils.toByteArray(incoming);
                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
                    outgoing.setChunked(true);
                    response.setEntity(outgoing);
                } else {
                    StringEntity outgoing = new StringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        });
        this.server.start();
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());
        try {
            for (int r = 0; r < reqNo; r++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket, this.client.getParams());
                }
                BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
                byte[] data = (byte[]) testData.get(r);
                ByteArrayEntity outgoing = new ByteArrayEntity(data);
                outgoing.setChunked(true);
                post.setEntity(outgoing);
                HttpResponse response = this.client.execute(post, host, conn);
                byte[] received = EntityUtils.toByteArray(response.getEntity());
                byte[] expected = (byte[]) testData.get(r);
                assertEquals(expected.length, received.length);
                for (int i = 0; i < expected.length; i++) {
                    assertEquals(expected[i], received[i]);
                }
                if (!this.client.keepAlive(response)) {
                    conn.close();
                }
            }
            HttpConnectionMetrics cm = conn.getMetrics();
            assertEquals(reqNo, cm.getRequestCount());
            assertEquals(reqNo, cm.getResponseCount());
        } finally {
            conn.close();
            this.server.shutdown();
        }
    }
public void testSimpleHttpPostsHTTP10() throws Exception {
        int reqNo = 20;
        Random rnd = new Random();
        List testData = new ArrayList(reqNo);
        for (int i = 0; i < reqNo; i++) {
            int size = rnd.nextInt(5000);
            byte[] data = new byte[size];
            rnd.nextBytes(data);
            testData.add(data);
        }
        this.server.registerHandler("*", new HttpRequestHandler() {

            public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] data = EntityUtils.toByteArray(incoming);
                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
                    outgoing.setChunked(false);
                    response.setEntity(outgoing);
                } else {
                    StringEntity outgoing = new StringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        });
        this.server.start();
        this.client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());
        try {
            for (int r = 0; r < reqNo; r++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket, this.client.getParams());
                }
                BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
                byte[] data = (byte[]) testData.get(r);
                ByteArrayEntity outgoing = new ByteArrayEntity(data);
                post.setEntity(outgoing);
                HttpResponse response = this.client.execute(post, host, conn);
                assertEquals(HttpVersion.HTTP_1_0, response.getStatusLine().getProtocolVersion());
                byte[] received = EntityUtils.toByteArray(response.getEntity());
                byte[] expected = (byte[]) testData.get(r);
                assertEquals(expected.length, received.length);
                for (int i = 0; i < expected.length; i++) {
                    assertEquals(expected[i], received[i]);
                }
                if (!this.client.keepAlive(response)) {
                    conn.close();
                }
            }
            HttpConnectionMetrics cm = conn.getMetrics();
            assertEquals(reqNo, cm.getRequestCount());
            assertEquals(reqNo, cm.getResponseCount());
        } finally {
            conn.close();
            this.server.shutdown();
        }
    }
public void testHttpPostsWithExpectContinue() throws Exception {
        int reqNo = 20;
        Random rnd = new Random();
        List testData = new ArrayList(reqNo);
        for (int i = 0; i < reqNo; i++) {
            int size = rnd.nextInt(5000);
            byte[] data = new byte[size];
            rnd.nextBytes(data);
            testData.add(data);
        }
        this.server.registerHandler("*", new HttpRequestHandler() {

            public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] data = EntityUtils.toByteArray(incoming);
                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
                    outgoing.setChunked(true);
                    response.setEntity(outgoing);
                } else {
                    StringEntity outgoing = new StringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        });
        this.server.start();
        this.client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());
        try {
            for (int r = 0; r < reqNo; r++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket, this.client.getParams());
                }
                BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
                byte[] data = (byte[]) testData.get(r);
                ByteArrayEntity outgoing = new ByteArrayEntity(data);
                outgoing.setChunked(true);
                post.setEntity(outgoing);
                HttpResponse response = this.client.execute(post, host, conn);
                byte[] received = EntityUtils.toByteArray(response.getEntity());
                byte[] expected = (byte[]) testData.get(r);
                assertEquals(expected.length, received.length);
                for (int i = 0; i < expected.length; i++) {
                    assertEquals(expected[i], received[i]);
                }
                if (!this.client.keepAlive(response)) {
                    conn.close();
                }
            }
            HttpConnectionMetrics cm = conn.getMetrics();
            assertEquals(reqNo, cm.getRequestCount());
            assertEquals(reqNo, cm.getResponseCount());
        } finally {
            conn.close();
            this.server.shutdown();
        }
    }
public String doUpload(@ParamName(name = "file") MultipartFile file, @ParamName(name = "uploadDirectory") String _uploadDirectory) throws IOException {
        String sessionId = (String) RuntimeAccess.getInstance().getSession().getAttribute("SESSION_ID");
        String tempUploadDir = MewitProperties.getTemporaryUploadDirectory();
        if (!tempUploadDir.endsWith("/") && !tempUploadDir.endsWith("\\")) {
            tempUploadDir += "\\";
        }
        String fileName = null;
        int position = file.getOriginalFilename().lastIndexOf(".");
        if (position <= 0) {
            fileName = java.util.UUID.randomUUID().toString();
        } else {
            fileName = java.util.UUID.randomUUID().toString() + file.getOriginalFilename().substring(position);
        }
        File outputFile = new File(tempUploadDir, fileName);
        log(INFO, "writing the content of uploaded file to: " + outputFile);
        FileOutputStream fos = new FileOutputStream(outputFile);
        IOUtils.copy(file.getInputStream(), fos);
        file.getInputStream().close();
        fos.close();
        return doUploadFile(sessionId, outputFile, file.getOriginalFilename());
    }
private String doUploadFile(String sessionId, File file, String originalFileName) throws UnsupportedEncodingException, IOException {
        log(INFO, sessionId);
        log(INFO, file.getPath());
        DefaultHttpClient httpclient = new DefaultHttpClient();
        UploadFileRequest request = new UploadFileRequest();
        request.setSessionId(sessionId);
        request.setDirectory(UUID.randomUUID().toString());
        request.setFileName(originalFileName);
        URL url = file.toURI().toURL();
        URLConnection urlCon = url.openConnection();
        XStream writer = new XStream();
        writer.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        writer.alias("UploadFileRequest", UploadFileRequest.class);
        XStream reader = new XStream();
        reader.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        reader.alias("UploadFileResponse", UploadFileResponse.class);
        String strRequest = URLEncoder.encode(reader.toXML(request), "UTF-8");
        HttpPost httppost = new HttpPost(MewitProperties.getMewitUrl() + "/resources/uploadFile?REQUEST=" + strRequest);
        FileEntity fileEntity = new FileEntity(file, urlCon.getContentType());
        httppost.setEntity(fileEntity);
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = URLDecoder.decode(EntityUtils.toString(entity), "UTF-8");
            log(INFO, result);
            UploadFileResponse oResponse = (UploadFileResponse) reader.fromXML(result);
            return oResponse.getFile();
        }
        return null;
    }
public void readPage(String search) {
        InputStream is = null;
        try {
            URL url = new URL("http://www.english-german-dictionary.com/index.php?search=" + search.trim());
            is = url.openStream();
            InputStreamReader isr = new InputStreamReader(is, "ISO-8859-15");
            Scanner scan = new Scanner(isr);
            String str = new String();
            String translate = new String();
            String temp;
            while (scan.hasNextLine()) {
                temp = (scan.nextLine());
                if (temp.contains("<td style='padding-top:4px;' class='ergebnisse_res'>")) {
                    int anfang = temp.indexOf("-->") + 3;
                    temp = temp.substring(anfang);
                    temp = temp.substring(0, temp.indexOf("<!--"));
                    translate = temp.trim();
                } else if (temp.contains("<td style='' class='ergebnisse_art'>") || temp.contains("<td style='' class='ergebnisse_art_dif'>") || temp.contains("<td style='padding-top:4px;' class='ergebnisse_art'>")) {
                    if (searchEnglish == false && searchGerman == false) {
                        searchEnglish = temp.contains("<td style='' class='ergebnisse_art'>");
                        searchGerman = temp.contains("<td style='' class='ergebnisse_art_dif'>");
                    }
                    int anfang1 = temp.lastIndexOf("'>") + 2;
                    temp = temp.substring(anfang1, temp.lastIndexOf("</td>"));
                    String to = temp.trim() + " ";
                    temp = scan.nextLine();
                    int anfang2 = temp.lastIndexOf("\">") + 2;
                    temp = (to != null ? to : "") + temp.substring(anfang2, temp.lastIndexOf("</a>"));
                    str += translate + " - " + temp + "\n";
                    germanList.add(translate);
                    englishList.add(temp.trim());
                }
            }
            if (searchEnglish) {
                List<String> temp2 = englishList;
                englishList = germanList;
                germanList = temp2;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (is != null) try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
private void album(String albumTitle, String albumNbSong, URL url) {
        try {
            if (color == SWT.COLOR_WHITE) {
                color = SWT.COLOR_GRAY;
            } else {
                color = SWT.COLOR_WHITE;
            }
            url.openConnection();
            InputStream is = url.openStream();
            Image coverPicture = new Image(this.getDisplay(), is);
            Composite albumComposite = new Composite(main, SWT.NONE);
            albumComposite.setLayout(new FormLayout());
            FormData data = new FormData();
            data.left = new FormAttachment(0, 5);
            data.right = new FormAttachment(100, -5);
            if (prevCompo == null) {
                data.top = new FormAttachment(0, 0);
            } else {
                data.top = new FormAttachment(prevCompo, 0, SWT.BOTTOM);
            }
            albumComposite.setLayoutData(data);
            albumComposite.setBackground(Display.getDefault().getSystemColor(color));
            Label cover = new Label(albumComposite, SWT.LEFT);
            cover.setText("cover");
            cover.setImage(coverPicture);
            data = new FormData(75, 75);
            cover.setLayoutData(data);
            Label title = new Label(albumComposite, SWT.CENTER);
            title.setFont(new Font(this.getDisplay(), "Arial", 10, SWT.BOLD));
            title.setText(albumTitle);
            data = new FormData();
            data.bottom = new FormAttachment(50, -5);
            data.left = new FormAttachment(cover, 5);
            title.setBackground(Display.getDefault().getSystemColor(color));
            title.setLayoutData(data);
            Label nbSong = new Label(albumComposite, SWT.LEFT | SWT.BOLD);
            nbSong.setFont(new Font(this.getDisplay(), "Arial", 8, SWT.ITALIC));
            nbSong.setText("Release date : " + albumNbSong);
            data = new FormData();
            data.top = new FormAttachment(50, 5);
            data.left = new FormAttachment(cover, 5);
            nbSong.setBackground(Display.getDefault().getSystemColor(color));
            nbSong.setLayoutData(data);
            prevCompo = albumComposite;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }