Search in sources :

Example 41 with Date

use of java.util.Date in project che by eclipse.

the class ProjectService method exportFile.

@GET
@Path("/export/file/{path:.*}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response exportFile(@ApiParam(value = "Path to resource to be imported") @PathParam("path") String path) throws NotFoundException, ForbiddenException, ServerException {
    final FileEntry file = projectManager.asFile(path);
    if (file == null) {
        throw new NotFoundException("File not found " + path);
    }
    final VirtualFile virtualFile = file.getVirtualFile();
    return Response.ok(virtualFile.getContent(), TIKA.detect(virtualFile.getName())).lastModified(new Date(virtualFile.getLastModificationDate())).header(HttpHeaders.CONTENT_LENGTH, Long.toString(virtualFile.getLength())).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + virtualFile.getName() + '"').build();
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) NotFoundException(org.eclipse.che.api.core.NotFoundException) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 42 with Date

use of java.util.Date in project che by eclipse.

the class GitHubKeyUploader method uploadKey.

@Override
public void uploadKey(String publicKey) throws IOException, UnauthorizedException {
    final OAuthToken token = tokenProvider.getToken("github", EnvironmentContext.getCurrent().getSubject().getUserId());
    if (token == null || token.getToken() == null) {
        LOG.debug("Token not found, user need to authorize to upload key.");
        throw new UnauthorizedException("To upload SSH key you need to authorize.");
    }
    StringBuilder answer = new StringBuilder();
    final String url = String.format("https://api.github.com/user/keys?access_token=%s", token.getToken());
    final List<GitHubKey> gitHubUserPublicKeys = getUserPublicKeys(url, answer);
    for (GitHubKey gitHubUserPublicKey : gitHubUserPublicKeys) {
        if (publicKey.startsWith(gitHubUserPublicKey.getKey())) {
            return;
        }
    }
    final Map<String, String> postParams = new HashMap<>(2);
    postParams.put("title", "IDE SSH Key (" + new SimpleDateFormat().format(new Date()) + ")");
    postParams.put("key", new String(publicKey.getBytes()));
    final String postBody = JsonHelper.toJson(postParams);
    LOG.debug("Upload public key: {}", postBody);
    int responseCode;
    HttpURLConnection conn = null;
    try {
        conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setInstanceFollowRedirects(false);
        conn.setRequestMethod(HttpMethod.POST);
        conn.setRequestProperty(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
        conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
        conn.setRequestProperty(HttpHeaders.CONTENT_LENGTH, String.valueOf(postBody.length()));
        conn.setDoOutput(true);
        try (OutputStream out = conn.getOutputStream()) {
            out.write(postBody.getBytes());
        }
        responseCode = conn.getResponseCode();
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
    LOG.debug("Upload key response code: {}", responseCode);
    if (responseCode != HttpURLConnection.HTTP_CREATED) {
        throw new IOException(String.format("%d: Failed to upload public key to https://github.com/", responseCode));
    }
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Date(java.util.Date) URL(java.net.URL) OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) HttpURLConnection(java.net.HttpURLConnection) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) GitHubKey(org.eclipse.che.plugin.github.shared.GitHubKey) SimpleDateFormat(java.text.SimpleDateFormat)

Example 43 with Date

use of java.util.Date in project tomcat by apache.

the class ExpiresFilter method getExpirationDate.

/**
     * <p>
     * Returns the expiration date of the given {@link XHttpServletResponse} or
     * {@code null} if no expiration date has been configured for the
     * declared content type.
     * </p>
     * <p>
     * {@code protected} for extension.
     * </p>
     *
     * @param response The Servlet response
     * @return the expiration date
     * @see HttpServletResponse#getContentType()
     */
protected Date getExpirationDate(XHttpServletResponse response) {
    String contentType = response.getContentType();
    // lookup exact content-type match (e.g.
    // "text/html; charset=iso-8859-1")
    ExpiresConfiguration configuration = expiresConfigurationByContentType.get(contentType);
    if (configuration != null) {
        Date result = getExpirationDate(configuration, response);
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("expiresFilter.useMatchingConfiguration", configuration, contentType, contentType, result));
        }
        return result;
    }
    if (contains(contentType, ";")) {
        // lookup content-type without charset match (e.g. "text/html")
        String contentTypeWithoutCharset = substringBefore(contentType, ";").trim();
        configuration = expiresConfigurationByContentType.get(contentTypeWithoutCharset);
        if (configuration != null) {
            Date result = getExpirationDate(configuration, response);
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("expiresFilter.useMatchingConfiguration", configuration, contentTypeWithoutCharset, contentType, result));
            }
            return result;
        }
    }
    if (contains(contentType, "/")) {
        // lookup major type match (e.g. "text")
        String majorType = substringBefore(contentType, "/");
        configuration = expiresConfigurationByContentType.get(majorType);
        if (configuration != null) {
            Date result = getExpirationDate(configuration, response);
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("expiresFilter.useMatchingConfiguration", configuration, majorType, contentType, result));
            }
            return result;
        }
    }
    if (defaultExpiresConfiguration != null) {
        Date result = getExpirationDate(defaultExpiresConfiguration, response);
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("expiresFilter.useDefaultConfiguration", defaultExpiresConfiguration, contentType, result));
        }
        return result;
    }
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("expiresFilter.noExpirationConfiguredForContentType", contentType));
    }
    return null;
}
Also used : Date(java.util.Date)

Example 44 with Date

use of java.util.Date in project hbase by apache.

the class MasterDumpServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
    assert master != null : "No Master in context!";
    response.setContentType("text/plain");
    OutputStream os = response.getOutputStream();
    PrintWriter out = new PrintWriter(os);
    out.println("Master status for " + master.getServerName() + " as of " + new Date());
    out.println("\n\nVersion Info:");
    out.println(LINE);
    dumpVersionInfo(out);
    out.println("\n\nTasks:");
    out.println(LINE);
    TaskMonitor.get().dumpAsText(out);
    out.println("\n\nServers:");
    out.println(LINE);
    dumpServers(master, out);
    out.println("\n\nRegions-in-transition:");
    out.println(LINE);
    dumpRIT(master, out);
    out.println("\n\nExecutors:");
    out.println(LINE);
    dumpExecutors(master.getExecutorService(), out);
    out.println("\n\nStacks:");
    out.println(LINE);
    out.flush();
    PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
    Threads.printThreadInfo(ps, "");
    ps.flush();
    out.println("\n\nMaster configuration:");
    out.println(LINE);
    Configuration conf = master.getConfiguration();
    out.flush();
    conf.writeXml(os);
    os.flush();
    out.println("\n\nRecent regionserver aborts:");
    out.println(LINE);
    master.getRegionServerFatalLogBuffer().dumpTo(out);
    out.println("\n\nLogs");
    out.println(LINE);
    long tailKb = getTailKbParam(request);
    LogMonitoring.dumpTailOfLogs(out, tailKb);
    out.println("\n\nRS Queue:");
    out.println(LINE);
    if (isShowQueueDump(conf)) {
        RSDumpServlet.dumpQueue(master, out);
    }
    out.flush();
}
Also used : PrintStream(java.io.PrintStream) Configuration(org.apache.hadoop.conf.Configuration) OutputStream(java.io.OutputStream) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 45 with Date

use of java.util.Date in project hbase by apache.

the class MobUtils method getFirstDayOfMonth.

/**
   * Get the first day of the input date's month
   * @param calendar Calendar object
   * @param date The date to find out its first day of that month
   * @return The first day in the month
   */
public static Date getFirstDayOfMonth(final Calendar calendar, final Date date) {
    calendar.setTime(date);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    Date firstDayInMonth = calendar.getTime();
    return firstDayInMonth;
}
Also used : Date(java.util.Date)

Aggregations

Date (java.util.Date)33499 Test (org.junit.Test)8112 SimpleDateFormat (java.text.SimpleDateFormat)4502 ArrayList (java.util.ArrayList)3177 Calendar (java.util.Calendar)2351 HashMap (java.util.HashMap)1985 IOException (java.io.IOException)1914 File (java.io.File)1649 ParseException (java.text.ParseException)1578 List (java.util.List)1106 DateFormat (java.text.DateFormat)1022 Map (java.util.Map)983 GregorianCalendar (java.util.GregorianCalendar)884 Test (org.junit.jupiter.api.Test)853 HashSet (java.util.HashSet)576 Test (org.testng.annotations.Test)527 Timestamp (java.sql.Timestamp)458 BigDecimal (java.math.BigDecimal)436 LocalDate (java.time.LocalDate)423 DateTime (org.joda.time.DateTime)391