Example usage for java.lang Long MAX_VALUE

List of usage examples for java.lang Long MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Long MAX_VALUE.

Prototype

long MAX_VALUE

To view the source code for java.lang Long MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value a long can have, 263-1.

Usage

From source file:TimeFormat.java

/**
 * test//  w  w  w.  j a  va2s  .  com
 * 
 * 
 * @param args
 */
public static void main(String args[]) {
    String FORMAT = "D 'days,' HH 'hours,' mm 'minutes and ' ss 'seconds, 'zz 'milliseconds'";

    System.out.println(TimeFormat.format(FORMAT, 1000));
    System.out.println("ONE SECOND: " + TimeFormat.ONE_SECOND);
    System.out.println("ONE MINUTE: " + TimeFormat.ONE_MINUTE);
    System.out.println("ONE HOUR:   " + TimeFormat.ONE_HOUR);
    System.out.println("ONE DAY:    " + TimeFormat.ONE_DAY);

    for (int c = 0; c <= 5; c++) {
        System.out.println("Round to: " + c);
        System.out.println("Time: " + TimeFormat.valueOf(Long.MAX_VALUE, c));
        System.out.println("Time: " + TimeFormat.valueOf(1236371400, c));
        System.out.println("Time: " + TimeFormat.format(FORMAT, 1236371400));
        System.out.println("Time: " + TimeFormat.valueOf(123613700, c));
        System.out.println("Time: " + TimeFormat.valueOf(700, c));
        System.out.println("Time: " + TimeFormat.valueOf(2001, c));
        System.out.println("Time: " + TimeFormat.valueOf(2101, c));
        System.out.println("Time: " + TimeFormat.valueOf(15, c));
        System.out.println("Time: " + TimeFormat.valueOf(999, c));
        System.out.println("Time: " + TimeFormat.valueOf(10000, c));
        System.out.println("Time: " + TimeFormat.valueOf(ONE_MINUTE * 10, c));
        System.out.println("Time: " + TimeFormat.valueOf(ONE_DAY * 10 + 101, c));
        System.out.println("Time: " + TimeFormat.valueOf(ONE_HOUR * 10, c));
        System.out.println("Time: " + TimeFormat.valueOf(ONE_HOUR + ONE_DAY + (ONE_MINUTE * 2), c));
        System.out.println("Time: " + TimeFormat.format(FORMAT, ONE_HOUR + ONE_DAY + (ONE_MINUTE * 2)));
    }
}

From source file:com.basetechnology.s0.agentserver.field.IntField.java

public static Field fromJson(SymbolTable symbolTable, JSONObject fieldJson) {
    String type = fieldJson.optString("type");
    if (type == null || !(type.equals("int") || type.equals("integer")))
        return null;
    String name = fieldJson.has("name") ? fieldJson.optString("name") : null;
    String label = fieldJson.has("label") ? fieldJson.optString("label") : null;
    String description = fieldJson.has("description") ? fieldJson.optString("description") : null;
    long defaultValue = fieldJson.has("default_value") ? fieldJson.optLong("default_value") : 0;
    long minValue = fieldJson.has("min_value") ? fieldJson.optLong("min_value") : Long.MIN_VALUE;
    long maxValue = fieldJson.has("max_value") ? fieldJson.optLong("max_value") : Long.MAX_VALUE;
    int nominalWidth = fieldJson.has("nominal_width") ? fieldJson.optInt("nominal_width") : 0;
    String compute = fieldJson.has("compute") ? fieldJson.optString("compute") : null;
    return new IntField(symbolTable, name, label, description, defaultValue, minValue, maxValue, nominalWidth,
            compute);//ww  w .jav a2s . com
}

From source file:com.compomics.pladipus.controller.setup.InstallActiveMQ.java

private void downloadActiveMQ() throws IOException, ZipException {

    //File downloadFile = PladipusFileDownloadingService.downloadFile(link, activeMQFolder);

    if (!activeMQFolder.exists() & !activeMQFolder.mkdirs()) {
        throw new IOException("could not make install folder");
    }//w  w  w  .  j av  a  2s .c  o  m

    URL website = new URL(link);
    Path downloadFile = Files.createTempFile("activemqdownload", null);
    try (ReadableByteChannel rbc = Channels.newChannel(website.openStream());
            FileOutputStream fos = new FileOutputStream(downloadFile.toFile())) {
        //todo replace with loop and replace Long.MAX_VALUE with buffer size?
        if (fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE) != 0) {
            try (FileInputStream fis = new FileInputStream(downloadFile.toFile())) {
                if (DigestUtils.md5Hex(fis).equals("4b844f588672e6616bd6f006253d6148")) {
                    ZipFile zipFile = new ZipFile(downloadFile.toFile());
                    zipFile.extractAll(activeMQFolder.getPath());

                } else {
                    throw new IOException("md5 digest did not match, aborting");
                }
            }
        }
    }
}

From source file:com.splunk.shuttl.archiver.bucketlock.SimpleFileLock.java

private FileLock getLockWithErrorHandling(boolean shared) {
    try {/*from ww  w.  j ava2 s  .co m*/
        return fileChannel.tryLock(0, Long.MAX_VALUE, shared);
    } catch (OverlappingFileLockException e) {
        return null; // Expected when locking twice.
    } catch (ClosedChannelException e) {
        throw new LockAlreadyClosedException(
                "Lock was already closed. " + "Cannot lock this lock that was closed.");
    } catch (IOException e) {
        logger.debug(did("Tried locking FailedBucketsLock", "Got IOException", "To lock the file",
                "file_channel", fileChannel, "exception", e));
        throw new RuntimeException(e);
    }
}

From source file:com.netflix.suro.queue.FileQueue4Sink.java

@Override
public long remainingCapacity() {
    return Long.MAX_VALUE; // theoretically unlimited
}

From source file:info.archinnov.achilles.it.TestEntityWithComplexIndices.java

@Test
public void should_query_using_simple_index() throws Exception {
    //Given/*from   w w w  .  ja v  a 2s . c om*/
    final Long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    scriptExecutor.executeScriptTemplate("EntityWithIndicesForJSON/insertRows.cql", ImmutableMap.of("id", id));

    //When
    final List<EntityWithComplexIndices> actual = manager.indexed().select().allColumns_FromBaseTable().where()
            .simpleIndex().Eq("313").getList();

    //Then
    assertThat(actual).hasSize(1);
    final EntityWithComplexIndices entity = actual.get(0);
    assertThat(entity.getFullIndexOnCollection()).containsExactly("313");
}

From source file:io.undertow.server.ReadTimeoutTestCase.java

@Test
public void testReadTimeout() throws IOException, InterruptedException {
    DefaultServer.setRootHandler(new HttpHandler() {
        @Override/*from   w w  w.  ja  v  a 2 s  .  c  o  m*/
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            final StreamSinkChannel response = exchange.getResponseChannel();
            final StreamSourceChannel request = exchange.getRequestChannel();
            try {
                request.setOption(Options.READ_TIMEOUT, 100);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            request.getReadSetter()
                    .set(ChannelListeners.drainListener(Long.MAX_VALUE, new ChannelListener<Channel>() {
                        @Override
                        public void handleEvent(final Channel channel) {
                            new StringWriteChannelListener("COMPLETED") {
                                @Override
                                protected void writeDone(final StreamSinkChannel channel) {
                                    exchange.endExchange();
                                }
                            }.setup(response);
                        }
                    }, new ChannelExceptionHandler<StreamSourceChannel>() {
                        @Override
                        public void handleException(final StreamSourceChannel channel, final IOException e) {
                            exchange.endExchange();
                            exception = e;
                            errorLatch.countDown();
                        }
                    }));
            request.wakeupReads();

        }
    });

    final TestHttpClient client = new TestHttpClient();
    try {
        HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL());
        post.setEntity(new AbstractHttpEntity() {

            @Override
            public InputStream getContent() throws IOException, IllegalStateException {
                return null;
            }

            @Override
            public void writeTo(final OutputStream outstream) throws IOException {
                for (int i = 0; i < 5; ++i) {
                    outstream.write('*');
                    outstream.flush();
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }

            @Override
            public boolean isStreaming() {
                return true;
            }

            @Override
            public boolean isRepeatable() {
                return false;
            }

            @Override
            public long getContentLength() {
                return 5;
            }
        });
        post.addHeader(Headers.CONNECTION_STRING, "close");
        try {
            client.execute(post);
        } catch (IOException e) {

        }
        if (errorLatch.await(5, TimeUnit.SECONDS)) {
            Assert.assertEquals(ReadTimeoutException.class, exception.getClass());
        } else {
            Assert.fail("Read did not time out");
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.cloudbees.hudson.plugins.folder.computed.EventOutputStreamsTest.java

public void test(final boolean aFlush, final boolean bFlush) throws Exception {
    final File file = work.newFile();
    final EventOutputStreams instance = new EventOutputStreams(new EventOutputStreams.OutputFile() {
        @NonNull/*from  w  ww . j  a va 2  s .  c o  m*/
        @Override
        public File get() {
            return file;
        }
    }, 250, TimeUnit.MILLISECONDS, 8192, false, Long.MAX_VALUE, 0);
    Thread t1 = new Thread() {
        public void run() {
            OutputStream os = instance.get();
            try {
                PrintWriter pw = new PrintWriter(os, aFlush);
                for (int i = 0; i < 10000; i += 1) {
                    pw.println(String.format("%1$05dA", i));
                }
                pw.flush();
            } catch (Throwable e) {
                e.printStackTrace(System.err);
            } finally {
                IOUtils.closeQuietly(os);
            }
        }
    };
    Thread t2 = new Thread() {
        public void run() {
            OutputStream os = instance.get();
            try {
                PrintWriter pw = new PrintWriter(os, bFlush);
                for (int i = 0; i < 10000; i += 1) {
                    pw.println(String.format("%1$05dB", i));
                }
                pw.flush();
            } catch (Throwable e) {
                e.printStackTrace(System.err);
            } finally {
                IOUtils.closeQuietly(os);
            }
        }
    };
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    List<String> as = new ArrayList<String>();
    List<String> bs = new ArrayList<String>();
    for (String line : FileUtils.readLines(file)) {
        assertThat("Line does not have both thread output: '" + StringEscapeUtils.escapeJava(line) + "'",
                line.matches("^\\d+[AB](\\d+[AB])+$"), is(false));
        assertThat("Line does not contain a null character: '" + StringEscapeUtils.escapeJava(line) + "'",
                line.indexOf(0), is(-1));
        if (line.endsWith("A")) {
            as.add(line);
        } else if (line.endsWith("B")) {
            bs.add(line);
        } else {
            fail("unexpected line: '" + StringEscapeUtils.escapeJava(line) + "'");
        }
    }
    List<String> sorted = new ArrayList<String>(as);
    Collections.sort(sorted);
    assertThat(as, is(sorted));
    sorted = new ArrayList<String>(bs);
    Collections.sort(sorted);
    assertThat(bs, is(sorted));
}

From source file:com.hazelcast.simulator.boot.SimulatorInstaller.java

void install() {
    File simulatorHome = new File(FileUtils.getUserHomePath(), "hazelcast-simulator-" + version);
    System.setProperty("SIMULATOR_HOME", simulatorHome.getAbsolutePath());

    System.out.println("Installing Simulator: " + version);

    File userHome = getUserHome();
    try {//  ww w.  j a  v a2  s  .  c o  m
        if (version.endsWith("SNAPSHOT")) {
            File archive = new File(
                    format("%s/.m2/repository/com/hazelcast/simulator/dist/%s/dist-%s-dist.tar.gz", userHome,
                            version, version));

            if (archive.exists()) {
                simulatorHome.delete();
                decompress(archive);
            } else if (!simulatorHome.exists()) {
                throw new IllegalStateException(
                        "Could not install simulator, archive: " + archive.getAbsolutePath() + " not found");
            }
        } else if (!simulatorHome.exists()) {
            File archive = new File(getUserHome(), format("hazelcast-simulator-%s-dist.tar.gz", version));

            URL url = new URL(format(
                    "http://repo1.maven.org/maven2/" + "com/hazelcast/simulator/dist/%s/dist-%s-dist.tar.gz",
                    version, version));
            ReadableByteChannel rbc = Channels.newChannel(url.openStream());
            System.out.printf("File [%s] doesn't exist; downloading\n", archive.getAbsolutePath());
            FileOutputStream fos = new FileOutputStream(archive);
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

            decompress(archive);
            archive.delete();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:info.archinnov.achilles.test.integration.tests.InsertStrategyIT.java

@Test
public void should_insert_all_fields() throws Exception {
    //Given/*from  w  ww .  j  a v a 2s  .co m*/
    Long id = RandomUtils.nextLong(0, Long.MAX_VALUE);
    CompleteBean entity = new CompleteBean();
    entity.setId(id);
    entity.setName("John");
    entity.setAge(33L);

    //When
    manager1.insert(entity);
    entity.setName("Helen");
    entity.setAge(null);

    manager1.insert(entity);

    //Then
    final CompleteBean found = manager1.find(CompleteBean.class, id);

    assertThat(found.getName()).isEqualTo("Helen");
    assertThat(found.getAge()).isNull();
}