List of usage examples for org.apache.http.protocol HTTP US_ASCII
String US_ASCII
To view the source code for org.apache.http.protocol HTTP US_ASCII.
Click Source Link
From source file:org.vietspider.net.apache.AbstractSessionInputBuffer.java
protected void init(final InputStream _instream, int buffersize, final HttpParams params) { if (_instream == null) { throw new IllegalArgumentException("Input stream may not be null"); }/* w w w.j a va 2s . c o m*/ if (buffersize <= 0) { throw new IllegalArgumentException("Buffer size may not be negative or zero"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.instream = _instream; this.buffer = new byte[buffersize]; this.bufferpos = 0; this.bufferlen = 0; this.linebuffer = new ByteArrayBuffer(buffersize); this.charset = HttpProtocolParams.getHttpElementCharset(params); // this.timeoutSocket = params.getBooleanParameter("vietspider.socket.timeout", false); this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII) || this.charset.equalsIgnoreCase(HTTP.ASCII); this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.metrics = new HttpTransportMetricsImpl(); }
From source file:xdroid.ui.core.cache.LruDiskCache.java
/** * Opens the cache in {@code directory}, creating a cache if none exists * there.// www . ja va 2 s .c om * * @param directory a writable directory * @param valueCount the number of values per cache entry. Must be positive. * @param maxSize the maximum number of bytes this cache should use to store * @throws IOException if reading or writing the cache directory fails */ public static LruDiskCache open(File directory, int appVersion, int valueCount, long maxSize) throws IOException { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } if (valueCount <= 0) { throw new IllegalArgumentException("valueCount <= 0"); } // If a bkp file exists, use it instead. File backupFile = new File(directory, JOURNAL_FILE_BACKUP); if (backupFile.exists()) { File journalFile = new File(directory, JOURNAL_FILE); // If journal file also exists just delete backup file. if (journalFile.exists()) { backupFile.delete(); } else { renameTo(backupFile, journalFile, false); } } // Prefer to pick up where we left off. LruDiskCache cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); if (cache.journalFile.exists()) { try { cache.readJournal(); cache.processJournal(); cache.journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(cache.journalFile, true), HTTP.US_ASCII)); return cache; } catch (Throwable journalIsCorrupt) { cache.delete(); } } // Create a new empty cache. directory.mkdirs(); cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); cache.rebuildJournal(); return cache; }
From source file:cn.isif.util_plus.cache.LruDiskCache.java
/** * Opens the cache in {@code directory}, creating a cache if none exists * there./* w w w. j a va 2 s . c om*/ * * @param directory a writable directory * @param valueCount the number of values per cache entry. Must be positive. * @param maxSize the maximum number of bytes this cache should use to store * @throws IOException if reading or writing the cache directory fails */ public static LruDiskCache open(File directory, int appVersion, int valueCount, long maxSize) throws IOException { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } if (valueCount <= 0) { throw new IllegalArgumentException("valueCount <= 0"); } // If a bkp file exists, use it instead. File backupFile = new File(directory, JOURNAL_FILE_BACKUP); if (backupFile.exists()) { File journalFile = new File(directory, JOURNAL_FILE); // If journal file also exists just delete backup file. if (journalFile.exists()) { backupFile.delete(); } else { renameTo(backupFile, journalFile, false); } } // Prefer to pick up where we left off. LruDiskCache cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); if (cache.journalFile.exists()) { try { cache.readJournal(); cache.processJournal(); cache.journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(cache.journalFile, true), HTTP.US_ASCII)); return cache; } catch (Throwable journalIsCorrupt) { LogUtils.e("DiskLruCache " + directory + " is corrupt: " + journalIsCorrupt.getMessage() + ", removing", journalIsCorrupt); cache.delete(); } } // Create a new empty cache. if (directory.exists() || directory.mkdirs()) { cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); cache.rebuildJournal(); } return cache; }
From source file:com.plusub.lib.other.LruDiskCache.java
/** * Opens the cache in {@code directory}, creating a cache if none exists * there./* w ww .j a v a 2 s . c om*/ * * @param directory a writable directory * @param valueCount the number of values per cache entry. Must be positive. * @param maxSize the maximum number of bytes this cache should use to store * @throws IOException if reading or writing the cache directory fails */ public static LruDiskCache open(File directory, int appVersion, int valueCount, long maxSize) throws IOException { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } if (valueCount <= 0) { throw new IllegalArgumentException("valueCount <= 0"); } // If a bkp file exists, use it instead. File backupFile = new File(directory, JOURNAL_FILE_BACKUP); if (backupFile.exists()) { File journalFile = new File(directory, JOURNAL_FILE); // If journal file also exists just delete backup file. if (journalFile.exists()) { backupFile.delete(); } else { renameTo(backupFile, journalFile, false); } } // Prefer to pick up where we left off. LruDiskCache cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); if (cache.journalFile.exists()) { try { cache.readJournal(); cache.processJournal(); cache.journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(cache.journalFile, true), HTTP.US_ASCII)); return cache; } catch (Throwable journalIsCorrupt) { Logger.e("DiskLruCache " + directory + " is corrupt: " + journalIsCorrupt.getMessage() + ", removing", journalIsCorrupt.getMessage()); cache.delete(); } } // Create a new empty cache. if (directory.exists() || directory.mkdirs()) { cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); cache.rebuildJournal(); } return cache; }
From source file:com.drive.student.xutils.util.core.LruDiskCache.java
/** * Opens the cache in {@code directory}, creating a cache if none exists * there./*from ww w .ja v a 2 s . com*/ * * @param directory a writable directory * @param valueCount the number of values per cache entry. Must be positive. * @param maxSize the maximum number of bytes this cache should use to store * @throws IOException if reading or writing the cache directory fails */ public static LruDiskCache open(File directory, int appVersion, int valueCount, long maxSize) throws IOException { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } if (valueCount <= 0) { throw new IllegalArgumentException("valueCount <= 0"); } // If a bkp file exists, use it instead. File backupFile = new File(directory, JOURNAL_FILE_BACKUP); if (backupFile.exists()) { File journalFile = new File(directory, JOURNAL_FILE); // If journal file also exists just delete backup file. if (journalFile.exists()) { backupFile.delete(); } else { renameTo(backupFile, journalFile, false); } } // Prefer to pick up where we left off. LruDiskCache cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); if (cache.journalFile.exists()) { try { cache.readJournal(); cache.processJournal(); cache.journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(cache.journalFile, true), HTTP.US_ASCII)); return cache; } catch (Throwable journalIsCorrupt) { LogUtils.e("DiskLruCache " + directory + " is corrupt: " + journalIsCorrupt.getMessage() + ", removing", journalIsCorrupt); cache.delete(); } } // Create a new empty cache. directory.mkdirs(); cache = new LruDiskCache(directory, appVersion, valueCount, maxSize); cache.rebuildJournal(); return cache; }
From source file:xdroid.ui.core.cache.LruDiskCache.java
/** * Creates a new journal that omits redundant information. This replaces the * current journal if it exists./* w ww .j a va 2 s. c o m*/ */ private synchronized void rebuildJournal() throws IOException { if (journalWriter != null) { journalWriter.close(); } Writer writer = null; try { writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFileTmp), HTTP.US_ASCII)); writer.write(MAGIC); writer.write("\n"); writer.write(VERSION_1); writer.write("\n"); writer.write(Integer.toString(appVersion)); writer.write("\n"); writer.write(Integer.toString(valueCount)); writer.write("\n"); writer.write("\n"); for (Entry entry : lruEntries.values()) { if (entry.currentEditor != null) { writer.write(DIRTY + ' ' + entry.diskKey + '\n'); } else { writer.write(CLEAN + ' ' + entry.diskKey + " t_" + entry.expiryTimestamp + entry.getLengths() + '\n'); } } } finally { try { if (writer != null) { writer.close(); } } catch (Exception e) { // TODO: handle exception } } if (journalFile.exists()) { renameTo(journalFile, journalFileBackup, true); } renameTo(journalFileTmp, journalFile, false); journalFileBackup.delete(); journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFile, true), HTTP.US_ASCII)); }
From source file:cn.isif.util_plus.cache.LruDiskCache.java
/** * Creates a new journal that omits redundant information. This replaces the * current journal if it exists./*from w w w . j a va 2 s .c om*/ */ private synchronized void rebuildJournal() throws IOException { if (journalWriter != null) { IOUtils.closeQuietly(journalWriter); } Writer writer = null; try { writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFileTmp), HTTP.US_ASCII)); writer.write(MAGIC); writer.write("\n"); writer.write(VERSION); writer.write("\n"); writer.write(Integer.toString(appVersion)); writer.write("\n"); writer.write(Integer.toString(valueCount)); writer.write("\n"); writer.write("\n"); for (Entry entry : lruEntries.values()) { if (entry.currentEditor != null) { writer.write(UPDATE + " " + entry.diskKey + '\n'); } else { writer.write(CLEAN + " " + entry.diskKey + " " + EXPIRY_PREFIX + entry.expiryTimestamp + entry.getLengths() + '\n'); } } } finally { IOUtils.closeQuietly(writer); } if (journalFile.exists()) { renameTo(journalFile, journalFileBackup, true); } renameTo(journalFileTmp, journalFile, false); journalFileBackup.delete(); journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFile, true), HTTP.US_ASCII)); }
From source file:com.drive.student.xutils.util.core.LruDiskCache.java
/** * Creates a new journal that omits redundant information. This replaces the * current journal if it exists./*from w ww. j ava 2 s . co m*/ */ private synchronized void rebuildJournal() throws IOException { if (journalWriter != null) { IOUtils.closeQuietly(journalWriter); } Writer writer = null; try { writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFileTmp), HTTP.US_ASCII)); writer.write(MAGIC); writer.write("\n"); writer.write(VERSION_1); writer.write("\n"); writer.write(Integer.toString(appVersion)); writer.write("\n"); writer.write(Integer.toString(valueCount)); writer.write("\n"); writer.write("\n"); for (Entry entry : lruEntries.values()) { if (entry.currentEditor != null) { writer.write(DIRTY + ' ' + entry.diskKey + '\n'); } else { writer.write(CLEAN + ' ' + entry.diskKey + " t_" + entry.expiryTimestamp + entry.getLengths() + '\n'); } } } finally { IOUtils.closeQuietly(writer); } if (journalFile.exists()) { renameTo(journalFile, journalFileBackup, true); } renameTo(journalFileTmp, journalFile, false); journalFileBackup.delete(); journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFile, true), HTTP.US_ASCII)); }
From source file:com.plusub.lib.other.LruDiskCache.java
/** * Creates a new journal that omits redundant information. This replaces the * current journal if it exists./*w w w . j a va2s. c o m*/ */ private synchronized void rebuildJournal() throws IOException { if (journalWriter != null) { try { journalWriter.close(); } catch (Throwable e) { } } Writer writer = null; try { writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFileTmp), HTTP.US_ASCII)); writer.write(MAGIC); writer.write("\n"); writer.write(VERSION); writer.write("\n"); writer.write(Integer.toString(appVersion)); writer.write("\n"); writer.write(Integer.toString(valueCount)); writer.write("\n"); writer.write("\n"); for (Entry entry : lruEntries.values()) { if (entry.currentEditor != null) { writer.write(UPDATE + " " + entry.diskKey + '\n'); } else { writer.write(CLEAN + " " + entry.diskKey + " " + EXPIRY_PREFIX + entry.expiryTimestamp + entry.getLengths() + '\n'); } } } finally { try { if (writer != null) writer.close(); } catch (Throwable e) { } } if (journalFile.exists()) { renameTo(journalFile, journalFileBackup, true); } renameTo(journalFileTmp, journalFile, false); journalFileBackup.delete(); journalWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(journalFile, true), HTTP.US_ASCII)); }