List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:com.datatorrent.lib.io.block.FSSliceReaderTest.java
@Test public void testBlockSize() throws IOException { long blockSize = 1000; Path path = new Path(testMeta.output); when(fileSystem.getDefaultBlockSize(path)).thenReturn(blockSize); Attribute.AttributeMap.DefaultAttributeMap readerAttr = new Attribute.AttributeMap.DefaultAttributeMap(); readerAttr.put(DAG.APPLICATION_ID, Long.toHexString(System.currentTimeMillis())); readerAttr.put(Context.OperatorContext.SPIN_MILLIS, 10); FSTestReader reader = new FSTestReader(); reader.setBasePath(testMeta.output); reader.setup(new OperatorContextTestHelper.TestIdOperatorContext(1, readerAttr)); Assert.assertEquals("Block Size", blockSize, (long) ((ReaderContext.FixedBytesReaderContext) reader.getReaderContext()).getLength()); }
From source file:org.apache.apex.malhar.lib.io.block.FSSliceReaderTest.java
@Test public void testBlockSize() throws IOException { long blockSize = 1000; Path path = new Path(testMeta.output); when(fileSystem.getDefaultBlockSize(path)).thenReturn(blockSize); Attribute.AttributeMap.DefaultAttributeMap readerAttr = new Attribute.AttributeMap.DefaultAttributeMap(); readerAttr.put(DAG.APPLICATION_ID, Long.toHexString(System.currentTimeMillis())); readerAttr.put(Context.OperatorContext.SPIN_MILLIS, 10); FSTestReader reader = new FSTestReader(); reader.setBasePath(testMeta.output); reader.setup(mockOperatorContext(1, readerAttr)); Assert.assertEquals("Block Size", blockSize, (long) ((ReaderContext.FixedBytesReaderContext) reader.getReaderContext()).getLength()); }
From source file:org.kepler.objectmanager.cache.DataCacheManager.java
/** * Return a temporary local LSID based on a string. * @param magicstring// w w w . java 2 s .c om * * @throws Exception */ private KeplerLSID getDataLSID(String magicstring) throws Exception { CRC32 c = new CRC32(); c.update(magicstring.getBytes()); String hexValue = Long.toHexString(c.getValue()); KeplerLSID lsid = new KeplerLSID("localdata", hexValue, 0L, 0L); return lsid; }
From source file:org.mrgeo.utils.HadoopUtils.java
/** * Creates a random string filled with hex values. *//* ww w. j a v a 2 s .c o m*/ public static synchronized String createRandomString(final int size) { // create a random string of hex characters. This will force the // sequence file to split appropriately. Certainly a hack, but shouldn't // cause much of a difference in speed, or storage. String randomString = ""; while (randomString.length() < size) { randomString += Long.toHexString(random.nextLong()); } return randomString.substring(0, size); }
From source file:org.apache.bookkeeper.bookie.CreateNewLogTest.java
@Test public void testCreateNewLogWithNoWritableLedgerDirs() throws Exception { ServerConfiguration conf = TestBKConfiguration.newServerConfiguration(); // Creating a new configuration with a number of ledger directories. conf.setLedgerDirNames(ledgerDirs);//from w w w .j ava 2 s . c om conf.setIsForceGCAllowWhenNoSpace(true); LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())); // Extracted from createNewLog() String logFileName = Long.toHexString(1) + ".log"; File dir = ledgerDirsManager.pickRandomWritableDir(); LOG.info("Picked this directory: {}", dir); File newLogFile = new File(dir, logFileName); newLogFile.createNewFile(); // Now let us move all dirs to filled dirs List<File> wDirs = ledgerDirsManager.getWritableLedgerDirs(); for (File tdir : wDirs) { ledgerDirsManager.addToFilledDirs(tdir); } EntryLogger el = new EntryLogger(conf, ledgerDirsManager); // Calls createNewLog, and with the number of directories we // are using, if it picks one at random it will fail. EntryLogManagerForSingleEntryLog entryLogManager = (EntryLogManagerForSingleEntryLog) el .getEntryLogManager(); entryLogManager.createNewLog(0L); LOG.info("This is the current log id: {}", entryLogManager.getCurrentLogId()); assertTrue("Wrong log id", entryLogManager.getCurrentLogId() > 1); }
From source file:org.apache.hadoop.hbase.TestZooKeeper.java
/** * See HBASE-1232 and http://wiki.apache.org/hadoop/ZooKeeper/FAQ#4. * @throws IOException// w ww .ja va2s .c om * @throws InterruptedException */ // fails frequently, disabled for now, see HBASE-6406 //@Test public void testClientSessionExpired() throws Exception { Configuration c = new Configuration(TEST_UTIL.getConfiguration()); // We don't want to share the connection as we will check its state c.set(HConstants.HBASE_CLIENT_INSTANCE_ID, "1111"); HConnection connection = HConnectionManager.getConnection(c); ZooKeeperWatcher connectionZK = getZooKeeperWatcher(connection); LOG.info("ZooKeeperWatcher= 0x" + Integer.toHexString(connectionZK.hashCode())); LOG.info("getRecoverableZooKeeper= 0x" + Integer.toHexString(connectionZK.getRecoverableZooKeeper().hashCode())); LOG.info("session=" + Long.toHexString(connectionZK.getRecoverableZooKeeper().getSessionId())); TEST_UTIL.expireSession(connectionZK); LOG.info("Before using zkw state=" + connectionZK.getRecoverableZooKeeper().getState()); // provoke session expiration by doing something with ZK try { connectionZK.getRecoverableZooKeeper().getZooKeeper().exists("/1/1", false); } catch (KeeperException ignored) { } // Check that the old ZK connection is closed, means we did expire States state = connectionZK.getRecoverableZooKeeper().getState(); LOG.info("After using zkw state=" + state); LOG.info("session=" + Long.toHexString(connectionZK.getRecoverableZooKeeper().getSessionId())); // It's asynchronous, so we may have to wait a little... final long limit1 = System.currentTimeMillis() + 3000; while (System.currentTimeMillis() < limit1 && state != States.CLOSED) { state = connectionZK.getRecoverableZooKeeper().getState(); } LOG.info("After using zkw loop=" + state); LOG.info("ZooKeeper should have timed out"); LOG.info("session=" + Long.toHexString(connectionZK.getRecoverableZooKeeper().getSessionId())); // It's surprising but sometimes we can still be in connected state. // As it's known (even if not understood) we don't make the the test fail // for this reason.) // Assert.assertTrue("state=" + state, state == States.CLOSED); // Check that the client recovered ZooKeeperWatcher newConnectionZK = getZooKeeperWatcher(connection); States state2 = newConnectionZK.getRecoverableZooKeeper().getState(); LOG.info("After new get state=" + state2); // As it's an asynchronous event we may got the same ZKW, if it's not // yet invalidated. Hence this loop. final long limit2 = System.currentTimeMillis() + 3000; while (System.currentTimeMillis() < limit2 && state2 != States.CONNECTED && state2 != States.CONNECTING) { newConnectionZK = getZooKeeperWatcher(connection); state2 = newConnectionZK.getRecoverableZooKeeper().getState(); } LOG.info("After new get state loop=" + state2); Assert.assertTrue(state2 == States.CONNECTED || state2 == States.CONNECTING); connection.close(); }
From source file:org.axiom_tools.crypto.SecurityToken.java
/** * Encrypts the content of this token./*from ww w .j a va2 s .c om*/ * * @return encrypted token content */ public byte[] toBytes() { StringBuffer buffer = new StringBuffer(); for (int index = 0; index < this.values.length; index++) { String hex = Long.toHexString(values[index]); int padWidth = Zeros.length() - hex.length(); buffer.append(Zeros.substring(0, padWidth) + hex); } String hexBuffer = buffer.toString(); return getCryptographer().encrypt(hexBuffer); }
From source file:com.mellanox.jxio.Msg.java
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("jxio.Msg(" + Long.toHexString(refToCObject) + ")"); sb.append("[msgIn=" + toStringBB(this.in)); sb.append(", msgOut=" + toStringBB(this.out)); sb.append(", msgPool=" + this.msgPool + "]"); return sb.toString(); }
From source file:org.geowebcache.util.ResponseUtils.java
/** * Happy ending, sets the headers and writes the response back to the client. *//* w ww .j a va2s. c o m*/ private static void writeData(ConveyorTile tile, RuntimeStats runtimeStats) throws IOException { HttpServletResponse servletResp = tile.servletResp; final HttpServletRequest servletReq = tile.servletReq; final CacheResult cacheResult = tile.getCacheResult(); int httpCode = HttpServletResponse.SC_OK; Resource blob = tile.getBlob(); String mimeType = tile.getMimeType().getMimeType(blob); servletResp.setHeader("geowebcache-cache-result", String.valueOf(cacheResult)); servletResp.setHeader("geowebcache-tile-index", Arrays.toString(tile.getTileIndex())); long[] tileIndex = tile.getTileIndex(); TileLayer layer = tile.getLayer(); GridSubset gridSubset = layer.getGridSubset(tile.getGridSetId()); BoundingBox tileBounds = gridSubset.boundsFromIndex(tileIndex); servletResp.setHeader("geowebcache-tile-bounds", tileBounds.toString()); servletResp.setHeader("geowebcache-gridset", gridSubset.getName()); servletResp.setHeader("geowebcache-crs", gridSubset.getSRS().toString()); final long tileTimeStamp = tile.getTSCreated(); final String ifModSinceHeader = servletReq.getHeader("If-Modified-Since"); // commons-httpclient's DateUtil can encode and decode timestamps formatted as per RFC-1123, // which is one of the three formats allowed for Last-Modified and If-Modified-Since headers // (e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'). See // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 final String lastModified = org.apache.commons.httpclient.util.DateUtil.formatDate(new Date(tileTimeStamp)); servletResp.setHeader("Last-Modified", lastModified); final Date ifModifiedSince; if (ifModSinceHeader != null && ifModSinceHeader.length() > 0) { try { ifModifiedSince = DateUtil.parseDate(ifModSinceHeader); // the HTTP header has second precision long ifModSinceSeconds = 1000 * (ifModifiedSince.getTime() / 1000); long tileTimeStampSeconds = 1000 * (tileTimeStamp / 1000); if (ifModSinceSeconds >= tileTimeStampSeconds) { httpCode = HttpServletResponse.SC_NOT_MODIFIED; blob = null; } } catch (DateParseException e) { if (log.isDebugEnabled()) { log.debug("Can't parse client's If-Modified-Since header: '" + ifModSinceHeader + "'"); } } } if (httpCode == HttpServletResponse.SC_OK && tile.getLayer().useETags()) { String ifNoneMatch = servletReq.getHeader("If-None-Match"); String hexTag = Long.toHexString(tileTimeStamp); if (ifNoneMatch != null) { if (ifNoneMatch.equals(hexTag)) { httpCode = HttpServletResponse.SC_NOT_MODIFIED; blob = null; } } // If we get here, we want ETags but the client did not have the tile. servletResp.setHeader("ETag", hexTag); } int contentLength = (int) (blob == null ? -1 : blob.getSize()); writeFixedResponse(servletResp, httpCode, mimeType, blob, cacheResult, contentLength, runtimeStats); }
From source file:org.jumpmind.symmetric.transport.http.HttpOutgoingTransport.java
public OutputStream openStream() { try {/*from w w w . j ava 2 s . co m*/ connection = HttpTransportManager.openConnection(url, basicAuthUsername, basicAuthPassword); if (streamOutputEnabled) { connection.setChunkedStreamingMode(streamOutputChunkSize); } connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); connection.setConnectTimeout(httpTimeout); connection.setReadTimeout(httpTimeout); boundary = Long.toHexString(System.currentTimeMillis()); if (!fileUpload) { connection.setRequestMethod("PUT"); connection.setRequestProperty("Accept-Encoding", "gzip"); if (useCompression) { connection.addRequestProperty("Content-Type", "gzip"); // application/x-gzip? } } else { connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); } os = connection.getOutputStream(); if (!fileUpload && useCompression) { os = new GZIPOutputStream(os) { { this.def.setLevel(compressionLevel); this.def.setStrategy(compressionStrategy); } }; } if (fileUpload) { final String fileName = "file.zip"; IOUtils.write("--" + boundary + CRLF, os); IOUtils.write( "Content-Disposition: form-data; name=\"binaryFile\"; filename=\"" + fileName + "\"" + CRLF, os); IOUtils.write("Content-Type: " + URLConnection.guessContentTypeFromName(fileName) + CRLF, os); IOUtils.write("Content-Transfer-Encoding: binary" + CRLF + CRLF, os); os.flush(); } return os; } catch (IOException ex) { throw new IoException(ex); } }