/** Met dans le cache le résultat de l'url indiquée */ public boolean putInCache(String url) throws Exception { // Lecture MyInputStream in = null; try { in = Util.openStream(url); byte buf[] = in.readFully(); // Nettoyage et Ecriture String id = codage(url); File g = new File(dir + Util.FS + id); g.delete(); RandomAccessFile f = null; try { f = new RandomAccessFile(dir + Util.FS + id, "rw"); f.write(buf); } finally { if (f != null) f.close(); } aladin.trace(3, "Put in cache [" + url + "]"); return true; } catch (Exception e) { if (aladin.levelTrace >= 3) e.printStackTrace(); } finally { if (in != null) in.close(); } return false; }
private InputStream buildInputStream() throws IOException { MyByteArrayStream is = new MyByteArrayStream(); // écriture préambule VOTable is.write("<?xml version=\"1.0\" ?>\n<VOTABLE>".getBytes()); // on écrit d'abord le contenu du buffer qui correspond au début du stream à créer if (beginStream != null) is.write(beginStream); // on écrit la suite byte[] buf = new byte[BUF_LENGTH]; int len; while (mis.available() > 0) { len = mis.read(buf); is.write(buf, 0, len); } return is.getInputStream(); }
private boolean getIsColorByPath(String path, boolean local) { String ext = inPNG ? ".png" : ".jpg"; MyInputStream in = null; try { if (local) return Util.isJPEGColored(path + Util.FS + "Norder3" + Util.FS + "Allsky" + ext); in = new MyInputStream(Util.openStream(path + "/Norder3/Allsky" + ext)); byte[] buf = in.readFully(); return Util.isColoredImage(buf); } catch (Exception e) { aladin.trace(3, "Allsky" + ext + " not found => assume B&W survey"); return false; } finally { try { if (in != null) in.close(); } catch (Exception e1) { } } }
private void moveNext() { if (in != null) { try { entry = (ZipArchiveEntry) in.getNextEntry(); while (entry != null) { if (!entry.getName().startsWith("_") && !entry.getName().startsWith(".") && isValid(entry.getName())) { next = new FileInputStreamWrapper(FilenameUtils.getName(entry.getName()), in); return; } entry = (ZipArchiveEntry) in.getNextEntry(); } } catch (IOException e) { LOG.warn("Error in zip: " + e); } in.forceClose(); } }
public static int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception { if (numIterations <= 0) return 0; if (dictionarySize < (1 << 18)) { System.out.println("\nError: dictionary size for benchmark must be >= 18 (256 KB)"); return 1; } System.out.print("\n Compressing Decompressing\n\n"); Encoder encoder = new Encoder(); Decoder decoder = new Decoder(); if (!encoder.SetDictionarySize(dictionarySize)) throw new Exception("Incorrect dictionary size"); int kBufferSize = dictionarySize + kAdditionalSize; int kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize; ByteArrayOutputStream propStream = new ByteArrayOutputStream(); encoder.WriteCoderProperties(propStream); byte[] propArray = propStream.toByteArray(); decoder.SetDecoderProperties2(propArray); CBenchRandomGenerator rg = new CBenchRandomGenerator(); rg.Set(kBufferSize); rg.Generate(); Common.CRC crc = new Common.CRC(); crc.Init(); crc.Update(rg.Buffer, 0, rg.BufferSize); CProgressInfo progressInfo = new CProgressInfo(); progressInfo.ApprovedStart = dictionarySize; long totalBenchSize = 0; long totalEncodeTime = 0; long totalDecodeTime = 0; long totalCompressedSize = 0; MyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize); byte[] compressedBuffer = new byte[kCompressedBufferSize]; MyOutputStream compressedStream = new MyOutputStream(compressedBuffer); CrcOutStream crcOutStream = new CrcOutStream(); MyInputStream inputCompressedStream = null; int compressedSize = 0; for (int i = 0; i < numIterations; i++) { progressInfo.Init(); inStream.reset(); compressedStream.reset(); encoder.Code(inStream, compressedStream, -1, -1, progressInfo); long encodeTime = System.currentTimeMillis() - progressInfo.Time; if (i == 0) { compressedSize = compressedStream.size(); inputCompressedStream = new MyInputStream(compressedBuffer, compressedSize); } else if (compressedSize != compressedStream.size()) throw (new Exception("Encoding error")); if (progressInfo.InSize == 0) throw (new Exception("Internal ERROR 1282")); long decodeTime = 0; for (int j = 0; j < 2; j++) { inputCompressedStream.reset(); crcOutStream.Init(); long outSize = kBufferSize; long startTime = System.currentTimeMillis(); if (decoder.Code(inputCompressedStream, crcOutStream, outSize, null) != HRESULT.S_OK) throw (new Exception("Decoding Error")); ; decodeTime = System.currentTimeMillis() - startTime; if (crcOutStream.GetDigest() != crc.GetDigest()) throw (new Exception("CRC Error")); } long benchSize = kBufferSize - (long) progressInfo.InSize; PrintResults(dictionarySize, encodeTime, benchSize, false, 0); System.out.print(" "); PrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize); System.out.println(); totalBenchSize += benchSize; totalEncodeTime += encodeTime; totalDecodeTime += decodeTime; totalCompressedSize += compressedSize; } System.out.println("---------------------------------------------------"); PrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0); System.out.print(" "); PrintResults( dictionarySize, totalDecodeTime, kBufferSize * (long) numIterations, true, totalCompressedSize); System.out.println(" Average"); return 0; }