Skip to content

Commit

Permalink
'#1859 add entry creation timestamp info as metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdalla committed Nov 8, 2023
1 parent 757ceab commit ed5c0c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public class CacheIndexParser extends AbstractParser {
public static final String CACHE_URL = METADATA_PREFIX + ":chromeCacheUrl";
private static final String CACHE_ENTRY_NAME = METADATA_PREFIX + ":cacheEntryName";

public static final String CACHE_ENTRY_CREATED = METADATA_PREFIX + ":created";
public static final String CACHE_ENTRY_COUNT = METADATA_PREFIX + ":numEntries";

@Override
public Set<MediaType> getSupportedTypes(ParseContext context) {
return SUPPORTED_TYPES;
Expand Down Expand Up @@ -122,6 +124,7 @@ public void parse(InputStream indexFile, ContentHandler handler, Metadata metada
entryMeta.set(IS_CACHE_INDEX_ENTRY, Boolean.TRUE.toString());
entryMeta.set(CACHE_ENTRY_NAME, ce.getName());
entryMeta.set(CACHE_URL, ce.getRequestURL());
entryMeta.set(TikaCoreProperties.CREATED, ce.getCreationTime());

for (Map.Entry<String, String> entry : httpResponse.entrySet()) {
entryMeta.set(entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class CacheEntry {
private int reuseCount;
private int refetchCount;
private int state;
private long creationTime;
private Date creationTime;
private int keyDataSize;
private CacheAddr longKeyAddressCacheAddress;
private long longKeyAddress;
Expand Down Expand Up @@ -66,7 +67,7 @@ public int getRefetchCount() {
return refetchCount;
}

public long getCreationTime() {
public Date getCreationTime() {
return creationTime;
}

Expand Down Expand Up @@ -124,7 +125,8 @@ public CacheEntry(InputStream is, List<IItemReader> dataFiles, List<IItemReader>
reuseCount = Index.read4bytes(is);
refetchCount = Index.read4bytes(is);
state = Index.read4bytes(is);
creationTime = Index.read8bytes(is);

creationTime = Index.readDate(is);
keyDataSize = Index.read4bytes(is);
longKeyAddress = Index.readUnsignedInt(is);
longKeyAddressCacheAddress = new CacheAddr(longKeyAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.poi.hpsf.Filetime;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -247,4 +250,11 @@ public static long read8bytes(InputStream is) throws IOException {
return ByteBuffer.wrap(b).getLong() & 0xffffffffffffffffL;
}

public static Date readDate(InputStream is) throws IOException {
byte[] buf = new byte[8];
is.read(buf);
long timestamp = new LittleEndianByteArrayInputStream(buf).readLong();
return Filetime.filetimeToDate(timestamp * 10);
}

}

0 comments on commit ed5c0c0

Please sign in to comment.