Example usage for java.io PrintWriter write

List of usage examples for java.io PrintWriter write

Introduction

In this page you can find the example usage for java.io PrintWriter write.

Prototype

public void write(String s) 

Source Link

Document

Writes a string.

Usage

From source file:nersc.greenseas.portlet.GreenseasPortlet.java

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {
    System.out.println("Calling serveResource");
    resourceResponse.setContentType("text/javascript");
    String uri = resourceRequest.getParameter("fileID");
    String requestType = resourceRequest.getParameter("requestType");
    System.out.println("requestType:'" + requestType + "'");
    String opendapDataURL = resourceRequest.getParameter("opendapDataURL");
    if (requestType != null) {
        if (requestType.equals("serveNetCDFFile")) {
            String location = resourceRequest.getParameter("fileID");
            if (location != null) {
                String[] folders = { "content", "gsadbc", "createdFiles" };
                String filePath = createDirectory(System.getProperty("catalina.base"), folders);
                for (int i = 0; i < location.length(); i++) {
                    char c = uri.charAt(i);
                    if (c < '0' || (c > '9' && c < 'A') || (c > 'Z' && c < 'a') || c > 'z')
                        throw new InvalidFileNameException(
                                "Invalid file name (illegal character:'" + c + "'):" + uri);
                }/*  w w w  . j av a 2  s  .  c o m*/
                String fileExtension = ".nc";
                location = filePath + location + fileExtension;
                resourceResponse.setContentType("application/octet-stream");
                resourceResponse.setProperty("Content-Disposition",
                        "attachment;filename=\"Greenseas_Downloaded_Parameters.nc\"");
                OutputStream out = resourceResponse.getPortletOutputStream();

                //               Content-Type: application/octet-stream
                //               Content-Disposition: attachment;filename=\"filename.xxx\"
                InputStream in = null;
                try {
                    in = new FileInputStream(new File(location));
                    if (in != null) {
                        byte[] buffer = new byte[4096];
                        int len;

                        while ((len = in.read(buffer)) != -1) {
                            out.write(buffer, 0, len);
                        }

                        out.flush();
                        System.out.println("Wrote nc file to outputstream");
                    }
                } catch (Exception e) {
                    // TODO: handle exception
                } finally {
                    if (in != null)
                        in.close();
                    if (out != null)
                        out.close();
                }
            }
            return;
        }
        if (uri != null || opendapDataURL != null) {
            if (opendapDataURL == null) {
                String[] folders = { "content", "gsadbc", "uploadedFiles" };
                String filePath = createDirectory(System.getProperty("catalina.base"), folders);
                for (int i = 0; i < uri.length(); i++) {
                    char c = uri.charAt(i);
                    if (c < '0' || (c > '9' && c < 'A') || (c > 'Z' && c < 'a') || c > 'z')
                        throw new InvalidFileNameException(
                                "Invalid file name (illegal character:'" + c + "'):" + uri);
                }
                String fileExtension = ".nc";
                uri = filePath + uri + fileExtension;
            } else {
                uri = opendapDataURL;
            }
            if (requestType.startsWith("getDataValuesOf:")) {
                System.out.println("requestType is getDataValuesOf:");
                Map<String, String[]> parameterMap = resourceRequest.getParameterMap();
                Map<Integer, Map<String, Double>> values = NetCDFReader.getDatavaluesFromNetCDFFile(uri,
                        parameterMap);
                if (values == null)
                    return;
                JSONObject jsonObject = new JSONObject(values);
                // System.out.println("Returning with jsonObject:");
                // System.out.println(jsonObject.toJSONString());

                PrintWriter writer = resourceResponse.getWriter();
                writer.write(jsonObject.toString());
                return;
            } else if (requestType.equals("getLayersFromNetCDFFile")) {
                System.out.println("requestType is getLayersFromNetCDFFile:");
                System.out.println("opendapDataURL:" + opendapDataURL);
                System.out.println("uri:" + uri);
                Map<String, String> values = NetCDFReader.getLayersFromRaster(uri);
                if (values == null) {
                    System.out.println("No values found!");
                    return;
                }
                JSONObject jsonObject = new JSONObject(values);

                System.out.println("Returning with jsonObject:");
                System.out.println(jsonObject.toJSONString());

                PrintWriter writer = resourceResponse.getWriter();
                writer.write(jsonObject.toString());
                return;
            } else if (requestType.equals("getMetaDimensions")) {
                System.out.println("getMetaDimensions:" + uri);
                String parameter = resourceRequest.getParameter("rasterParameter");
                if (parameter == null)
                    return;
                Map<String, Map<String, String>> values = NetCDFReader.getDimensionsFromRasterParameter(uri,
                        parameter);
                if (values == null)
                    return;
                JSONObject jsonObject = new JSONObject(values);

                System.out.println("Returning with jsonObject:");
                System.out.println(jsonObject.toJSONString());

                PrintWriter writer = resourceResponse.getWriter();
                writer.write(jsonObject.toString());
                return;
            } else if (requestType.equals("loadFileFromID")) {
                //TODO: fix security hole
                System.out.println(uri);
                JSONObject jsonObject = new JSONObject();
                File f = new File(uri);
                boolean exists = f.exists();
                // sleep for 1 seconds to mitigate brute force attacks
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
                jsonObject.put("fileIDExists", exists);
                PrintWriter writer = resourceResponse.getWriter();
                writer.write(jsonObject.toString());
                return;
            }
        }
        if (requestType.equals("getLonghurstPolygon")) {
            Map<String, String> values = new HashMap<String, String>();
            String region = resourceRequest.getParameter("longhurstRegion");
            System.out.println("getLonghurstPolygon:" + region);
            String polygon = DatabaseProperties.getLonghurstPolygon(region);
            values.put(region, polygon);
            JSONObject jsonObject = new JSONObject(values);

            System.out.println("Returning with polygon!=null:" + (polygon != null));

            PrintWriter writer = resourceResponse.getWriter();
            writer.write(jsonObject.toString());
            return;
        } else if (requestType.equals("createNetCDFUsingH.1")) {
            JSONParser parser = new JSONParser();
            JSONArray jsonA = null;
            JSONObject jsonO = null;
            int numberOfFeatures = 0;
            try {
                jsonA = (JSONArray) parser.parse(resourceRequest.getParameter("data"));
                String variablesString = resourceRequest.getParameter("variables");
                numberOfFeatures = Integer.parseInt(resourceRequest.getParameter("numberOfFeatures"));
                System.out.println(variablesString);
                jsonO = (JSONObject) parser.parse(variablesString);
            } catch (ParseException e) {
            }
            String[] folders = { "content", "gsadbc", "createdFiles" };
            String filePath = createDirectory(System.getProperty("catalina.base"), folders);

            String fileID = NetCDFWriter.createNetCDF(jsonA, jsonO, numberOfFeatures, filePath);
            Map<String, String> values = new HashMap<String, String>();

            values.put("fileID", fileID);
            JSONObject jsonObject = new JSONObject(values);

            /*resourceResponse.setContentType("application/x-netcdf");
            resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
                    
            OutputStream out = resourceResponse.getPortletOutputStream();
                    
            InputStream in = new FileInputStream(new File(location));
                    
            byte[] buffer = new byte[4096];
            int len;
                    
            while ((len = in.read(buffer)) != -1) {
               out.write(buffer, 0, len);
            }
                    
            out.flush();
            in.close();
            out.close();*/
            System.out.println("Returning with fileID" + fileID);

            PrintWriter writer = resourceResponse.getWriter();
            writer.write(jsonObject.toString());
            return;
        } else if (requestType.equals("getLonghurstPolygon")) {
            Map<String, String> values = new HashMap<String, String>();
            String region = resourceRequest.getParameter("longhurstRegion");
            System.out.println("getLonghurstPolygon:" + region);
            String polygon = DatabaseProperties.getLonghurstPolygon(region);
            values.put(region, polygon);
            JSONObject jsonObject = new JSONObject(values);

            System.out.println("Returning with polygon!=null:" + (polygon != null));

            PrintWriter writer = resourceResponse.getWriter();
            writer.write(jsonObject.toString());
            return;
        } else if (requestType.equals("updateTreeWithInventoryNumbers")) {
            String urlS = resourceRequest.getParameter("url");
            String region = resourceRequest.getParameter("gsadbcRegionFilterPlaceHolder");
            if (region != null) {
                region = region.substring(51, region.length() - 13);
            }
            JSONParser parser = new JSONParser();
            JSONObject jsonO = null;
            try {
                jsonO = (JSONObject) parser.parse(resourceRequest.getParameter("data"));
            } catch (ParseException e) {
            }
            String charset = "UTF-8";
            int numberOfThreads = 4;
            Set<?> entrySet = jsonO.keySet();
            ArrayList<Map<String, String>> responseMaps = new ArrayList<Map<String, String>>();
            ArrayList<Map<String, String>> requestMaps = new ArrayList<Map<String, String>>();
            for (int i = 0; i < numberOfThreads; i++) {
                responseMaps.add(new HashMap<String, String>());
                requestMaps.add(new HashMap<String, String>());
            }

            int thredd = 0;
            for (Object o : entrySet) {
                String key = (String) o;
                String request = (String) jsonO.get(key);
                requestMaps.get(thredd).put(key, request);
                thredd = (thredd + 1) % numberOfThreads;
            }
            ArrayList<GetNumberOfFeatures> threadds = new ArrayList<GetNumberOfFeatures>();
            for (int i = 0; i < numberOfThreads; i++) {
                GetNumberOfFeatures runnable = new GetNumberOfFeatures(responseMaps.get(i), requestMaps.get(i),
                        charset, urlS, i, region);
                Thread thread = new Thread(runnable);
                thread.start();
                threadds.add(runnable);
            }
            while (true) {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                boolean done = true;
                for (int i = 0; i < numberOfThreads; i++) {
                    if (!threadds.get(i).done) {
                        done = false;
                        break;
                    }
                }
                if (done)
                    break;
            }
            Map<String, String> responseMap = new HashMap<String, String>();

            for (int i = 0; i < numberOfThreads; i++) {
                responseMap.putAll(responseMaps.get(i));
            }
            JSONObject jsonObject = new JSONObject(responseMap);
            PrintWriter writer = resourceResponse.getWriter();
            writer.write(jsonObject.toString());
            return;
        }
    } else {

    }
}

From source file:com.globalsight.connector.blaise.BlaiseCreateJobHandler.java

@ActionHandler(action = "uploadAttachment", formClass = "")
public void uploadAttachment(HttpServletRequest request, HttpServletResponse response, Object form)
        throws Exception {
    FileUploader uploader = new FileUploader();
    File file = uploader.upload(request);

    getSessionManager(request).setAttribute("uploadAttachment", file.getAbsolutePath());

    PrintWriter writer = response.getWriter();
    writer.write("<script type='text/javascript'>window.parent.addAttachment(' ')</script>;");

    pageReturn();//from  w  ww .ja v  a2s  .com
}

From source file:com.cognifide.aet.rest.ConfigsServlet.java

/***
 * Returns JSON representation of Suite based on correlationId or suite name.
 * If suite name is provided, then newest version of JSON is returned.
 *
 * @param req//from w ww  .  j a v  a 2 s .c o  m
 * @param resp
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    LOGGER.debug("GET, req: '{}'", req);
    PrintWriter responseWriter = retrieveResponseWriter(req, resp);
    if (responseWriter != null) {
        resp.setContentType("application/json");
        String configType = StringUtils.substringAfter(req.getRequestURI(), Helper.getConfigsPath())
                .replace(Helper.PATH_SEPARATOR, "");
        String reportDomain = reportConfigurationManager.getReportDomain();

        if (COMMUNICATION_SETTINGS_PARAM.equals(configType)) {
            JmsEndpointConfig jmsEndpointConfig = jmsConnection.getEndpointConfig();
            CommunicationSettings communicationSettings = new CommunicationSettings(jmsEndpointConfig,
                    reportDomain);
            responseWriter.write(new Gson().toJson(communicationSettings));
        } else if (LIST_PARAM.equals(configType)) {
            resp.setContentType("text/html; charset=utf-8");
            resp.setHeader("User-Agent",
                    "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36");
            responseWriter.write(new SuitesListProvider(metadataDAO, reportDomain).listSuites());
        } else if (LOCKS_PARAM.equals(configType)) {
            responseWriter.write(getLocks());
        } else {
            resp.setStatus(HttpURLConnection.HTTP_BAD_REQUEST);
            responseWriter.write("Unable to get given config.");
        }
    } else {
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    flushResponseBuffer(req, resp);
}

From source file:edu.vt.vbi.patric.portlets.GenomeFinder.java

@SuppressWarnings("unchecked")
public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {

    String sraction = request.getParameter("sraction");

    if (sraction != null) {
        if (sraction.equals("save_params")) {

            Map<String, String> key = new HashMap<>();

            String genomeId = request.getParameter("genomeId");
            String taxonId = request.getParameter("taxonId");
            String cType = request.getParameter("cType");
            String cId = request.getParameter("cId");
            if (cType != null && cId != null && cType.equals("taxon") && !cId.equals("")) {
                taxonId = cId;//w w  w. j  av  a2  s.c om
            }
            String keyword = request.getParameter("keyword");
            String state = request.getParameter("state");
            String exact_search_term = request.getParameter("exact_search_term");
            String search_on = request.getParameter("search_on");

            if (genomeId != null && !genomeId.equals("")) {
                key.put("genomeId", genomeId);
            }
            if (taxonId != null && !taxonId.equals("")) {
                key.put("taxonId", taxonId);
            }
            if (keyword != null) {
                key.put("keyword", keyword.trim());
            }
            if (state != null) {
                key.put("state", state);
            }
            if (exact_search_term != null) {
                key.put("exact_search_term", exact_search_term);
            }
            if (search_on != null) {
                key.put("search_on", search_on);
            }

            if (!key.containsKey("genomeId") && cType != null && cType.equals("genome") && cId != null
                    && !cId.equals("")) {
                key.put("genomeId", cId);
            }
            if (!key.containsKey("taxonId") && cType != null && cType.equals("taxon") && cId != null
                    && !cId.equals("")) {
                key.put("taxonId", cId);
            }

            long pk = (new Random()).nextLong();

            SessionHandler.getInstance().set(SessionHandler.PREFIX + pk, jsonWriter.writeValueAsString(key));

            PrintWriter writer = response.getWriter();
            writer.write("" + pk);
            writer.close();
        } else if (sraction.equals("get_params")) {

            String ret = "";
            String pk = request.getParameter("pk");
            String json = SessionHandler.getInstance().get(SessionHandler.PREFIX + pk);
            if (json != null) {
                Map<String, String> key = jsonReader.readValue(json);
                ret = key.get("keyword");
            }

            PrintWriter writer = response.getWriter();
            writer.write("" + ret);
            writer.close();
        }
    } else {

        String need = request.getParameter("need");
        JSONObject jsonResult = new JSONObject();

        switch (need) {
        case "0": {
            // Getting Genome List
            String pk = request.getParameter("pk");
            Map data = processGenomeTab(request);

            Map<String, String> key = (Map) data.get("key");
            int numFound = (Integer) data.get("numFound");
            List<Genome> records = (List<Genome>) data.get("genomes");

            JSONArray docs = new JSONArray();
            for (Genome item : records) {
                docs.add(item.toJSONObject());
            }

            if (data.containsKey("facets")) {
                JSONObject facets = FacetHelper.formatFacetTree((Map) data.get("facets"));
                key.put("facets", facets.toJSONString());
                SessionHandler.getInstance().set(SessionHandler.PREFIX + pk,
                        jsonWriter.writeValueAsString(key));
            }

            jsonResult.put("results", docs);
            jsonResult.put("total", numFound);

            response.setContentType("application/json");
            PrintWriter writer = response.getWriter();
            jsonResult.writeJSONString(writer);
            writer.close();
            break;
        }
        case "1": {
            // getting Genome Sequence List
            Map data = processSequenceTab(request);

            int numFound = (Integer) data.get("numFound");
            List<GenomeSequence> sequences = (List<GenomeSequence>) data.get("sequences");

            JSONArray docs = new JSONArray();
            for (GenomeSequence item : sequences) {
                docs.add(item.toJSONObject());
            }

            jsonResult.put("results", docs);
            jsonResult.put("total", numFound);

            response.setContentType("application/json");
            PrintWriter writer = response.getWriter();
            jsonResult.writeJSONString(writer);
            writer.close();
            break;
        }
        case "tree": {

            String pk = request.getParameter("pk");
            String state;
            Map<String, String> key = jsonReader
                    .readValue(SessionHandler.getInstance().get(SessionHandler.PREFIX + pk));

            if (key.containsKey("state")) {
                state = key.get("state");
            } else {
                state = request.getParameter("state");
            }

            key.put("state", state);

            SessionHandler.getInstance().set(SessionHandler.PREFIX + pk, jsonWriter.writeValueAsString(key));

            JSONArray tree = new JSONArray();
            try {
                if (key.containsKey("facets") && !key.get("facets").isEmpty()) {

                    JSONObject facet_fields = (JSONObject) (new JSONParser()).parse(key.get("facets"));
                    DataApiHandler dataApi = new DataApiHandler(request);
                    tree = FacetHelper.processStateAndTree(dataApi, SolrCore.GENOME, key, need, facet_fields,
                            key.get("facet"), state, key.get("join"), 4);
                }
            } catch (ParseException e) {
                LOGGER.error(e.getMessage(), e);
            }

            response.setContentType("application/json");
            PrintWriter writer = response.getWriter();
            tree.writeJSONString(writer);
            writer.close();
            break;
        }
        case "tree_for_taxon": {
            // This is called by Taxon Overview page to faceted summary of genome under a specific taxa.

            String facet = request.getParameter("facet");
            String keyword = request.getParameter("keyword");

            Map<String, String> key = new HashMap<>();
            key.put("keyword", keyword);

            DataApiHandler dataApi = new DataApiHandler(request);
            SolrQuery query = dataApi.buildSolrQuery(key, null, facet, 0, 0, false); // build solr query

            LOGGER.debug("tree_for_taxon: [{}] {}", SolrCore.GENOME.getSolrCoreName(), query.toString());

            String apiResponse = dataApi.solrQuery(SolrCore.GENOME, query);

            Map resp = jsonReader.readValue(apiResponse);

            JSONObject facet_fields = FacetHelper.formatFacetTree((Map) resp.get("facet_counts"));
            JSONArray tree = FacetHelper.processStateAndTree(dataApi, SolrCore.GENOME, key, need, facet_fields,
                    facet, "", null, 4);

            response.setContentType("application/json");
            PrintWriter writer = response.getWriter();
            tree.writeJSONString(writer);
            writer.close();
            break;
        }
        case "getGenome": {
            // This is called by Genome Overview page to display genome metadata.

            DataApiHandler dataApi = new DataApiHandler(request);
            Genome genome = dataApi.getGenome(request.getParameter("id"));

            response.setContentType("application/json");
            PrintWriter writer = response.getWriter();
            if (genome != null) {
                genome.toJSONObject().writeJSONString(writer);
            }
            writer.close();
            break;
        }
        case "download": {
            List<String> tableHeader = new ArrayList<>();
            List<String> tableField = new ArrayList<>();
            JSONArray tableSource = new JSONArray();

            String fileName = "GenomeFinder";
            String fileFormat = request.getParameter("fileformat");
            //            String _tablesource = request.getParameter("tablesource");

            String aT = request.getParameter("aT");

            switch (aT) {
            case "0": {
                // genome
                Map data = processGenomeTab(request);
                List<Genome> genomes = (List<Genome>) data.get("genomes");

                for (Genome genome : genomes) {
                    tableSource.add(genome.toJSONObject());
                }

                tableHeader.addAll(DownloadHelper.getHeaderForGenomes());
                tableField.addAll(DownloadHelper.getFieldsForGenomes());
                break;
            }
            case "1": {
                // sequence
                Map data = processSequenceTab(request);
                List<GenomeSequence> sequences = (List<GenomeSequence>) data.get("sequences");

                for (GenomeSequence sequence : sequences) {
                    tableSource.add(sequence.toJSONObject());
                }

                tableHeader.addAll(DownloadHelper.getHeaderForGenomeSequence());
                tableField.addAll(DownloadHelper.getFieldsForGenomeSequence());
                break;
            }
            }

            ExcelHelper excel = new ExcelHelper("xssf", tableHeader, tableField, tableSource);
            excel.buildSpreadsheet();

            if (fileFormat.equalsIgnoreCase("xlsx")) {
                response.setContentType("application/octetstream");
                response.addProperty("Content-Disposition",
                        "attachment; filename=\"" + fileName + "." + fileFormat + "\"");

                excel.writeSpreadsheettoBrowser(response.getPortletOutputStream());
            } else if (fileFormat.equalsIgnoreCase("txt")) {

                response.setContentType("application/octetstream");
                response.addProperty("Content-Disposition",
                        "attachment; filename=\"" + fileName + "." + fileFormat + "\"");

                response.getPortletOutputStream().write(excel.writeToTextFile().getBytes());
            }
        }
        }
    }
}

From source file:edu.vt.vbi.patric.portlets.PathwayFinder.java

@SuppressWarnings("unchecked")
public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {

    String sraction = request.getParameter("sraction");

    if (sraction != null && sraction.equals("save_params")) {

        String search_on = request.getParameter("search_on");
        String keyword = request.getParameter("keyword");
        String taxonId = request.getParameter("taxonId");
        String algorithm = request.getParameter("algorithm");
        String genomeId = request.getParameter("genomeId");
        String feature_id = request.getParameter("feature_id");

        Map<String, String> key = new HashMap<>();

        if (search_on != null) {
            key.put("search_on", search_on.trim());
            if (search_on.equalsIgnoreCase("Map_ID")) {
                key.put("map", keyword.trim());
            } else if (search_on.equalsIgnoreCase("Ec_Number")) {
                key.put("ec_number", keyword.trim());
            } else if (search_on.equalsIgnoreCase("Keyword")) {
                key.put("keyword", keyword.trim());
            }/*ww w  . j  a  va2s  . c  o m*/
        }
        if (taxonId != null && !taxonId.equals("")) {
            key.put("taxonId", taxonId);
        }

        if (genomeId != null && !genomeId.equals("")) {
            key.put("genomeId", genomeId);
        }

        if (algorithm != null && !algorithm.equals("")) {
            key.put("algorithm", algorithm);
        }

        if (feature_id != null && !feature_id.equals("")) {
            key.put("feature_id", feature_id);
        }

        long pk = (new Random()).nextLong();

        SessionHandler.getInstance().set(SessionHandler.PREFIX + pk, jsonWriter.writeValueAsString(key));

        PrintWriter writer = response.getWriter();
        writer.write("" + pk);
        writer.close();
    } else {

        String need = request.getParameter("need");
        String pk = request.getParameter("pk");
        Map<String, String> key = null;
        if (pk != null && !pk.isEmpty()) {
            key = jsonReader.readValue(SessionHandler.getInstance().get(SessionHandler.PREFIX + pk));
        }

        DataApiHandler dataApi = new DataApiHandler(request);
        switch (need) {
        case "0":
            JSONObject jsonResult = processPathwayTab(dataApi, key.get("map"), key.get("ec_number"),
                    key.get("algorithm"), key.get("taxonId"), key.get("genomeId"), key.get("keyword"));
            response.setContentType("application/json");
            jsonResult.writeJSONString(response.getWriter());
            break;
        case "1":
            jsonResult = processEcNumberTab(dataApi, key.get("map"), key.get("ec_number"), key.get("algorithm"),
                    key.get("taxonId"), key.get("genomeId"), key.get("keyword"));
            response.setContentType("application/json");
            jsonResult.writeJSONString(response.getWriter());
            break;
        case "2":
            jsonResult = processGeneTab(dataApi, key.get("map"), key.get("ec_number"), key.get("algorithm"),
                    key.get("taxonId"), key.get("genomeId"), key.get("keyword"));
            response.setContentType("application/json");
            jsonResult.writeJSONString(response.getWriter());
            break;
        case "download":
            processDownload(request, response);
            break;
        case "downloadMapFeatureTable":
            processDownloadMapFeatureTable(request, response);
            break;
        }
    }
}

From source file:gr.demokritos.iit.cru.creativity.reasoning.diagrammatic.DiagrammaticComputationalTools.java

public HashSet<String> Graphs(JSONArray triples1, JSONArray triples2)
        throws FileNotFoundException, UnsupportedEncodingException, URISyntaxException, IOException,
        ParserConfigurationException, SAXException, XPathExpressionException, SQLException {
    // JSON a=new JSON();
    /*/*from  w w  w. j  a v  a 2 s .c  o m*/
     JSONArray users = new JSONArray();
     JSONObject obj1 = new JSONObject();
     obj1.put("c1", "rambo");
     obj1.put("rel", "likes");
     obj1.put("c2", "mambo");
     users.add(obj1);
     JSONObject obj2 = new JSONObject();
     obj2.put("c1", "rambo");
     obj2.put("rel", "likes");
     obj2.put("c2", "mambo");
     users.add(obj2);
     Object[] m = users.toArray();*/
    String filenameSource = "C:\\Users\\George\\Desktop\\projects\\diagrammatic\\triples1.rdf";// + System.currentTimeMillis() + 
    PrintWriter writer = new PrintWriter(filenameSource, "UTF-8");
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
            + "         xmlns=\"http://c2learn.eu/onto1#\"\n"///http://www.semagrow.eu/schemas/family#
            + "xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"
            + "         xmlns:owl=\"http://www.w3.org/2002/07/owl#\">\n" + "\n"
            + "<owl:Ontology rdf:about=\"\">\n" + "</owl:Ontology>\n" + "\n");

    for (Object triple : triples1) {
        // System.out.println(triple.toString());
        JSONObject jtriple = (JSONObject) triple;
        String concept = jtriple.get("c1").toString().toLowerCase();
        String relation = jtriple.get("rel").toString().toLowerCase();
        String subject = jtriple.get("c2").toString().toLowerCase();
        //  writer.write(" <owl:Class rdf:about=" + concept + ">\n"
        //          + "</owl:Class>\n");
        if (relation.equalsIgnoreCase("isA")) {
            writer.write("<owl:Class rdf:ID=\"" + concept + "\">\n");
            writer.write("<rdfs:label>" + concept + "</rdfs:label>\n");
            writer.write("<owl:subclassof rdf:resource=\"#" + subject + "\"/>\n");
            writer.write("</owl:Class>\n");
        }
        /*else {
         writer.write("<owl:ObjectProperty rdf:ID=\"" + relation + "\">\n");
         writer.write("<rdfs:range rdf:resource=\"#" + subject + "\"/>\n");
         writer.write("<rdfs:domain rdf:resource=\"#" + concept + "\"/>\n");
         writer.write("<rdfs:label>" + relation + "</rdfs:label>\n");
         writer.write("</owl:ObjectProperty>\n");
         }*/
        writer.write("\n");
    }
    writer.write("</rdf:RDF>");
    writer.close();

    String filenameTarget = "C:\\Users\\George\\Desktop\\projects\\diagrammatic\\triples2.rdf";////" + System.currentTimeMillis() + "

    writer = new PrintWriter(filenameTarget, "UTF-8");
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
            + "         xmlns=\"http://c2learn.eu/onto2#\"\n"//http://www.semagrow.eu/schemas/family#
            + "xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"
            + "         xmlns:owl=\"http://www.w3.org/2002/07/owl#\">\n" + "\n"
            + "<owl:Ontology rdf:about=\"\">\n" + "</owl:Ontology>\n" + "\n");
    for (Object triple : triples1) {
        // System.out.println(triple.toString());
        JSONObject jtriple = (JSONObject) triple;
        String concept = jtriple.get("c1").toString().toLowerCase();
        String relation = jtriple.get("rel").toString().toLowerCase();
        String subject = jtriple.get("c2").toString().toLowerCase();
        //  writer.write(" <owl:Class rdf:about=" + concept + ">\n"
        //          + "</owl:Class>\n");
        if (relation.equalsIgnoreCase("isA")) {
            writer.write("<owl:Class rdf:ID=\"" + concept + "\">\n");
            writer.write("<rdfs:label>" + concept + "</rdfs:label>\n");
            writer.write("<owl:subclassof rdf:resource=\"#" + subject + "\"/>\n");
            writer.write("</owl:Class>\n");
        }
        /*else {
         writer.write("<owl:ObjectProperty rdf:ID=\"" + relation + "\">\n");
         writer.write("<rdfs:range rdf:resource=\"#" + subject + "\"/>\n");
         writer.write("<rdfs:domain rdf:resource=\"#" + concept + "\"/>\n");
         writer.write("<rdfs:label>" + relation + "</rdfs:label>\n");
         writer.write("</owl:ObjectProperty>\n");
         }*/
        writer.write("\n");
    }
    writer.write("</rdf:RDF>");
    writer.close();

    String fileSeparator = "\\";
    //String oaeiDirectorySubsConceptsOnly = "C:/Users/antonis/Documents/NetBeansProjects/Synthesis/benchmarks";
    //   String oaeiDirectoryEqualsConceptsOnly = "C:/Users/antonis/Documents/NetBeansProjects/Synthesis/benchmarks";
    //String onto1 = "http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf";
    //String onto2 = "http://oaei.ontologymatching.org/2011/benchmarks/248/onto.rdf";
    String onto1 = filenameSource;// oaeiDirectoryEqualsConceptsOnly + fileSeparator + source + fileSeparator + "onto.rdf";;
    String onto2 = filenameTarget;// oaeiDirectoryEqualsConceptsOnly + fileSeparator + target + fileSeparator + "onto.rdf";;;

    onto1 = new File(onto1).toURI().toString();
    onto2 = new File(onto2).toURI().toString();

    String outputPath = System.getProperty("user.dir") + fileSeparator;
    // System.out.println(outputPath + "refalign.rdf");
    /*
             ResultsStorage storePrecisionCSR = new ResultsStorage("precisionCSR.txt");
             ResultsStorage storeRecalCSR = new ResultsStorage("recallCSR.txt");
            
             ResultsStorage storePrecisionVSM = new ResultsStorage("precisionVSM.txt");
             ResultsStorage storeRecalVSM = new ResultsStorage("recallVSM.txt");
            
             ResultsStorage storePrecisionCSRFactor = new ResultsStorage("precisionCSRFactor.txt");
             ResultsStorage storeRecalCSRFactor = new ResultsStorage("recallCSRFactor.txt");
            
             ResultsStorage storePrecisionVSMFactor = new ResultsStorage("precisionVSMFactor.txt");
             ResultsStorage storeRecalVSMFactor = new ResultsStorage("recallVSMFactor.txt");
            
             ResultsStorage storePrecisionCocluFactor = new ResultsStorage("precisionCocluFactor.txt");
             ResultsStorage storeRecalCocluFactor = new ResultsStorage("recallCocluFactor.txt");
            
             ResultsStorage storePrecisionCoclu = new ResultsStorage("precisionCoclu.txt");
             ResultsStorage storeRecalCoclu = new ResultsStorage("recallCoclu.txt");
            
             ResultsStorage storeCorrectCSR = new ResultsStorage("correctCSR.txt");
             ResultsStorage storeErrorCSR = new ResultsStorage("errorCSR.txt");
            
             ResultsStorage storeCorrectCoclu = new ResultsStorage("correctCoclu.txt");
             ResultsStorage storeErrorCoclu = new ResultsStorage("errorCoclu.txt");
            
             ResultsStorage storeCorrectCocluFactor = new ResultsStorage("correctCocluFactor.txt");
             ResultsStorage storeErrorCocluFactor = new ResultsStorage("errorCocluFactor.txt");
            
             ResultsStorage storeConfuzedEqualsForSubsCoclu = new ResultsStorage("ConfuzedEqualsForSubsCoclu.txt");
             ResultsStorage storeConfuzedEqualsForSubsCocluFactor = new ResultsStorage("ConfuzedEqualsForSubsCocluFactor.txt");
            
             ResultsStorage storeCorrectVSM = new ResultsStorage("correctVSM.txt");
             ResultsStorage storeErrorVSM = new ResultsStorage("errorVSM.txt");
             ResultsStorage storeCorrectCSRFactor = new ResultsStorage("correctCSRFactor.txt");
             ResultsStorage storeErrorCSRFactor = new ResultsStorage("errorCSRFactor.txt");
             ResultsStorage storeCorrectVSMFactor = new ResultsStorage("correctVSMFactor.txt");
             ResultsStorage storeErrorVSMFactor = new ResultsStorage("errorVSMFactor.txt");
             ResultsStorage storeConfuzedEqualsForSubsVSM = new ResultsStorage("ConfuzedEqualsForSubsVSM.txt");
             ResultsStorage storeConfuzedEqualsForSubsVSMFactor = new ResultsStorage("ConfuzedEqualsForSubsVSMFactor.txt");
             ResultsStorage storeConflictsEquals = new ResultsStorage("ConflictsEquals.txt");
             ResultsStorage storeConflictsSubs = new ResultsStorage("ConflictsSubs.txt");
             ResultsStorage storeMessages = new ResultsStorage("Messages.txt");
            
             ResultsStorage timeDuration = new ResultsStorage("timeDuration.txt");
            
             try {
             RunCoclouVsmCsrFactorGraphs synthesis = new RunCoclouVsmCsrFactorGraphs(onto1, onto2, outputPath,
             outputPath + "refalign.rdf", outputPath + "refalign.rdf", false, false, true,
             true,
             1, false, false, 0, 0.3, true, false, "over", "j48", false, false,
             10000, false, storePrecisionCSR, storeRecalCSR, storePrecisionVSM, storeRecalVSM,
             storePrecisionCSRFactor, storeRecalCSRFactor, storePrecisionVSMFactor, storeRecalVSMFactor,
             storeCorrectCSR, storeErrorCSR, storeCorrectVSM, storeErrorVSM, storeCorrectCSRFactor,
             storeErrorCSRFactor, storeCorrectVSMFactor, storeErrorVSMFactor, storeConfuzedEqualsForSubsVSM,
             storeConfuzedEqualsForSubsVSMFactor, storePrecisionCoclu, storeRecalCoclu, storeCorrectCoclu,
             storeErrorCoclu, storeConfuzedEqualsForSubsCoclu, storePrecisionCocluFactor, storeRecalCocluFactor,
             storeCorrectCocluFactor, storeErrorCocluFactor, storeConfuzedEqualsForSubsCocluFactor,
             timeDuration, storeConflictsEquals, storeConflictsSubs, storeMessages, true);
             synthesis.run();
             System.out.println(filenameTarget + " finished...");
             } catch (Exception e) {
             e.printStackTrace();
             }
            
             storePrecisionCSR.exportToFile();
             storeRecalCSR.exportToFile();
             storePrecisionVSM.exportToFile();
             storeRecalVSM.exportToFile();
             storePrecisionCSRFactor.exportToFile();
             storeRecalCSRFactor.exportToFile();
             storePrecisionVSMFactor.exportToFile();
             storeRecalVSMFactor.exportToFile();
             storeCorrectCSR.exportToFile();
             storeErrorCSR.exportToFile();
             storeCorrectVSM.exportToFile();
             storeErrorVSM.exportToFile();
             storeCorrectCSRFactor.exportToFile();
             storeErrorCSRFactor.exportToFile();
             storeCorrectVSMFactor.exportToFile();
             storeErrorVSMFactor.exportToFile();
             storeConfuzedEqualsForSubsVSM.exportToFile();
             storeConfuzedEqualsForSubsVSMFactor.exportToFile();
             storePrecisionCoclu.exportToFile();
             storeRecalCoclu.exportToFile();
             storeCorrectCoclu.exportToFile();
             storeErrorCoclu.exportToFile();
             storeConfuzedEqualsForSubsCoclu.exportToFile();
             storePrecisionCocluFactor.exportToFile();
             storeRecalCocluFactor.exportToFile();
             storeCorrectCocluFactor.exportToFile();
             storeErrorCocluFactor.exportToFile();
             storeConfuzedEqualsForSubsCocluFactor.exportToFile();
             timeDuration.exportToFile();
             storeConflictsEquals.exportToFile();
             storeConflictsSubs.exportToFile();
             storeMessages.exportToFile();
            
             storePrecisionCSR.close();
             storeRecalCSR.close();
             storePrecisionVSM.close();
             storeRecalVSM.close();
             storePrecisionCSRFactor.close();
             storeRecalCSRFactor.close();
             storePrecisionVSMFactor.close();
             storeRecalVSMFactor.close();
             storeCorrectCSR.close();
             storeErrorCSR.close();
             storeCorrectVSM.close();
             storeErrorVSM.close();
             storeCorrectCSRFactor.close();
             storeErrorCSRFactor.close();
             storeCorrectVSMFactor.close();
             storeErrorVSMFactor.close();
             storeConfuzedEqualsForSubsVSM.close();
             storeConfuzedEqualsForSubsVSMFactor.close();
             storePrecisionCoclu.close();
             storeRecalCoclu.close();
             storeCorrectCoclu.close();
             storeErrorCoclu.close();
             storeConfuzedEqualsForSubsCoclu.close();
             storePrecisionCocluFactor.close();
             storeRecalCocluFactor.close();
             storeCorrectCocluFactor.close();
             storeErrorCocluFactor.close();
             storeConfuzedEqualsForSubsCocluFactor.close();
             timeDuration.close();
             storeConflictsEquals.close();
             storeConflictsSubs.close();
             storeMessages.close();*/

    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    Document document = null;
    try {
        builder = builderFactory.newDocumentBuilder();
        document = (Document) builder.parse(new FileInputStream(outputPath + "alignment.rdf"));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    document.getDocumentElement().normalize();
    System.out.println("Root element :" + document.getDocumentElement().getNodeName());

    NodeList nl = document.getElementsByTagName("Cell");

    System.out.println("----------------------------");
    for (int temp = 0; temp < nl.getLength(); temp++) {

        Node nNode = nl.item(temp);

        System.out.println("\nCurrent Element :" + nNode.getNodeName());

        if (nNode.getNodeType() == Node.ELEMENT_NODE) {

            Element eElement = (Element) nNode;
            Element ent1 = (Element) eElement.getElementsByTagName("entity1").item(0);
            Element ent2 = (Element) eElement.getElementsByTagName("entity2").item(0);
            System.out.println(ent1.getAttribute("rdf:resource").split("#")[1]);
            System.out.println(ent2.getAttribute("rdf:resource").split("#")[1]);
            //  System.out.println("Staff id : " + eElement.getAttribute("rdf:resource"));
            System.out.println(
                    "relation : " + eElement.getElementsByTagName("relation").item(0).getTextContent());
            System.out
                    .println("measure : " + eElement.getElementsByTagName("measure").item(0).getTextContent());
            if (eElement.getElementsByTagName("relation").item(0).getTextContent().equalsIgnoreCase("=")) {
                Queries q = new Queries(this.conn);
                q.Insert(ent1.getAttribute("rdf:resource").split("#")[1],
                        ent2.getAttribute("rdf:resource").split("#")[1],
                        eElement.getElementsByTagName("measure").item(0).getTextContent());
            }
        }
    }
    //  String expression = "//Alignment//Cell";
    //   XPath xPath = XPathFactory.newInstance().newXPath();
    //   XPathExpression expr = xPath.compile(expression);

    //   NodeList nl = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
    //   for (Node n : nl) {
    //         System.out.println(n.getNodeName());
    //   }
    //  Object[] idsNode = node.evaluateXPath("//Alignment/Cell");
    //read a string value
    // Node node = (Node) xPath.compile(expression).evaluate(document, XPathConstants.NODE);
    /*
     BufferedReader in = new BufferedReader(new FileReader(outputPath + "alignment.rdf"));
     String line;
     while ((line = in.readLine()) != null) {
            
     }*/
    return new HashSet<String>();
}

From source file:net.openkoncept.vroom.VroomController.java

private void processRequestInvoke(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String method = request.getParameter(METHOD);
    String beanClass = request.getParameter(BEAN_CLASS);
    String var = request.getParameter(VAR);
    if (var == null || var.trim().length() == 0) {
        var = beanClass;
    }/*w  w w  .  java 2s .  c  om*/
    String scope = request.getParameter(SCOPE);
    if (scope == null || scope.trim().length() == 0) {
        if (var.equals(beanClass)) {
            scope = SCOPE_APPLICATION;
        } else {
            scope = SCOPE_SESSION;
        }
    }
    Object beanObject;
    Object object = null;
    try {
        Class clazz = Class.forName(beanClass);
        if (SCOPE_APPLICATION.equals(scope)) {
            beanObject = appBeanMap.get(var);
            if (beanObject == null) {
                beanObject = clazz.newInstance();
                appBeanMap.put(var, beanObject);
            }
        } else if (SCOPE_SESSION.equals(scope)) {
            beanObject = request.getSession().getAttribute(var);
            if (beanObject == null) {
                beanObject = clazz.newInstance();
                request.getSession().setAttribute(var, beanObject);
            }
        } else if (SCOPE_REQUEST.equals(scope)) {
            beanObject = request.getAttribute(var);
            if (beanObject == null) {
                beanObject = clazz.newInstance();
                request.setAttribute(var, beanObject);
            }
        } else {
            beanObject = clazz.newInstance();
        }
        String output;
        if ("getProperties".equals(method)) {
            object = beanObject;
        } else {
            Class[] signature = new Class[] { HttpServletRequest.class, HttpServletResponse.class };
            Method m;
            try {
                m = clazz.getMethod(method, signature);
                object = m.invoke(beanObject, new Object[] { request, response });
            } catch (Exception ex) {
                try {
                    m = clazz.getMethod(method, null);
                    object = m.invoke(beanObject, null);
                } catch (Exception ex2) {
                    try {
                        signature = new Class[] { HttpServletRequest.class };
                        m = clazz.getMethod(method, signature);
                        object = m.invoke(beanObject, new Object[] { request });
                    } catch (NoSuchMethodException ex3) {
                        throw new ServletException("Invocation Failed for method [" + method + "]", ex);
                    } catch (InvocationTargetException ex3) {
                        throw new ServletException("Invocation Failed for method [" + method + "]", ex);
                    }
                }
            }
            if (object == null) {
                object = "";
            }
        }
        JSONObject jo = VroomUtilities.convertObjectToJSONObject(object);
        jo.put("contextPath", request.getContextPath());
        jo.put("sessionId", request.getSession().getId());
        jo.put("locale", VroomUtilities.convertObjectToJSONObject(request.getLocale()));
        output = jo.toString();
        String encoding = request.getHeader("response-encoding");
        if (encoding == null || encoding.trim().length() == 0) {
            encoding = request.getCharacterEncoding();
        }
        response.setContentType(JSON_MIME_TYPE);
        if (encoding != null) {
            VroomUtilities.safeCall(response, "setCharacterEncoding", new Class[] { String.class },
                    new Object[] { encoding });
            //                response.setCharacterEncoding(encoding);
        }
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.write(output);
        } catch (IOException e) {
            throw new ServletException(e);
        } finally {
            if (out != null) {
                out.close();
            }
        }
    } catch (ClassNotFoundException ex) {
        throw new ServletException("Invocation Failed for method [" + method + "]", ex);
    } catch (InstantiationException ex) {
        throw new ServletException("Invocation Failed for method [" + method + "]", ex);
    } catch (IllegalAccessException ex) {
        throw new ServletException("Invocation Failed for method [" + method + "]", ex);
    } catch (JSONException ex) {
        throw new ServletException("Invalid JSON Object [" + object + "]", ex);
    }
}

From source file:com.ephesoft.gxt.admin.server.ImportDocumentTypeUploadServlet.java

/**
 * This API is used to write content in temp file.
 * /*from   ww w .  j  a v a  2s  . co m*/
 * @param item {@link FileItem} uploaded file item.
 * @param filePath {@link String} to create temporary file.
 * @param printWriter {@link PrintWriter}.
 * @return {@link File} temporary file.
 */
private File copyItemContentInFile(final FileItem item, final String filePath, final PrintWriter printWriter) {
    File tempZipFile = null;
    OutputStream out = null;
    InputStream instream = null;
    try {
        instream = item.getInputStream();
        tempZipFile = new File(filePath);
        if (tempZipFile.exists()) {
            tempZipFile.delete();
        }
        out = new FileOutputStream(tempZipFile);
        final byte buf[] = new byte[1024];
        int len;
        while ((len = instream.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
    } catch (final FileNotFoundException e) {
        printWriter.write("Unable to create the export folder.Please try again.");
    } catch (final IOException e) {
        printWriter.write("Unable to read the file.Please try again.");
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (final IOException ioe) {
                log.error("Could not close stream for file." + tempZipFile);
            }
        }
        if (instream != null) {
            try {
                instream.close();
            } catch (final IOException ioe) {
                log.error("Could not close stream for file." + filePath);
            }
        }
    }
    return tempZipFile;
}

From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java

private byte[] createMemoryFile(String content) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(bos);
    writer.write(content);
    writer.flush();/*from  w w w .  j  av  a  2s .c om*/
    writer.close();

    byte[] data = bos.toByteArray();
    bos.close();
    return data;
}

From source file:edu.ku.brc.af.core.db.DBTableIdMgr.java

/**
 * //from   w ww  . j av a  2 s  . c o  m
 */
public void dumpTablesAsCSV() {
    boolean checkMM = true;
    try {
        PrintWriter pw = new PrintWriter("TablesAndField.csv");
        for (DBTableInfo ti : getTables()) {
            pw.write("\"" + ti.getName() + "\",,\"" + ti.getTitle() + "\",\"" + ti.getDescription() + "\","
                    + (checkMM ? "Mismatch" : "") + "\n");
            for (DBFieldInfo fi : ti.getFields()) {
                pw.write(",\"" + fi.getName() + "\",\"" + fi.getTitle() + "\",\""
                        + (StringUtils.isNotEmpty(fi.getDescription()) ? fi.getDescription() : "") + "\",\""
                        + fi.getType() + "\"");
                if (checkMM) {
                    if (fi.getColumn().startsWith("Number")) {
                        if (StringUtils.contains(fi.getType(), "Byte")
                                || StringUtils.contains(fi.getType(), "Short")
                                || StringUtils.contains(fi.getType(), "Integer")
                                || StringUtils.contains(fi.getType(), "Long")
                                || StringUtils.contains(fi.getType(), "Float")
                                || StringUtils.contains(fi.getType(), "Double")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    } else if (fi.getColumn().startsWith("Text")) {
                        if (StringUtils.contains(fi.getType(), "String")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    } else if (fi.getColumn().startsWith("Yes")) {
                        if (StringUtils.contains(fi.getType(), "Boolean")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    } else if (fi.getColumn().startsWith("Remark")) {
                        if (StringUtils.contains(fi.getType(), "text")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    }
                }
                pw.write("\n");
            }
            for (DBRelationshipInfo ri : ti.getRelationships()) {
                pw.write(",\"" + ri.getName() + "\",\"" + ri.getTitle() + "\",\""
                        + (StringUtils.isNotEmpty(ri.getDescription()) ? ri.getDescription() : "") + "\",\""
                        + ri.getType() + "\"\n");
            }
        }

        pw.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}