List of usage examples for java.io DataInput readLong
long readLong() throws IOException;
From source file:org.apache.isis.objectstore.nosql.db.file.server.FileServer.java
private void syncConnection(final Socket connection, final int readTimeout) { try {/*from w w w .ja va 2s.co m*/ final CRC32 crc32 = new CRC32(); final DataOutput output = new DataOutputStream(connection.getOutputStream()); final DataInput input = new DataInputStream(new CheckedInputStream(connection.getInputStream(), crc32)); if (input.readByte() != INIT) { return; } final LogRange logFileRange = Util.logFileRange(); final long lastId = logFileRange.noLogFile() ? -1 : logFileRange.getLast(); output.writeLong(lastId); do { if (input.readByte() != RECOVERY_LOG) { return; } crc32.reset(); final long logId = input.readLong(); final File file = Util.tmpLogFile(logId); LOG.info("syncing recovery file: " + file.getName()); final BufferedOutputStream fileOutput = new BufferedOutputStream(new FileOutputStream(file)); final byte[] buffer = new byte[8092]; int length; while ((length = input.readInt()) > 0) { input.readFully(buffer, 0, length); fileOutput.write(buffer, 0, length); } fileOutput.close(); final long calculatedChecksum = crc32.getValue(); final long sentChecksum = input.readLong(); if (calculatedChecksum != sentChecksum) { throw new NoSqlStoreException("Checksum didn't match during download of " + file.getName()); } recover(file); final File renameTo = Util.logFile(logId); file.renameTo(renameTo); } while (true); } catch (final NoSqlStoreException e) { LOG.error("file server failure", e); } catch (final IOException e) { LOG.error("networking failure", e); } catch (final RuntimeException e) { LOG.error("request failure", e); } finally { try { connection.close(); } catch (final IOException e) { LOG.warn("failure to close connection", e); } } // TODO restart }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiUriResource serialized with writeURI and return it. * * @param input DataInput source//from w w w . ja v a 2s . c om * @return a KiWiUriResource * @throws IOException */ public static KiWiUriResource readURI(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { int prefixMode = input.readByte(); String uriPrefix = ""; String uriSuffix = DataIO.readString(input); switch (prefixMode) { case PREFIX_XSD: uriPrefix = XSD.NAMESPACE; break; case PREFIX_RDF: uriPrefix = RDF.NAMESPACE; break; case PREFIX_RDFS: uriPrefix = RDFS.NAMESPACE; break; case PREFIX_SKOS: uriPrefix = SKOS.NAMESPACE; break; case PREFIX_DC: uriPrefix = DC.NAMESPACE; break; case PREFIX_DCT: uriPrefix = DCTERMS.NAMESPACE; break; case PREFIX_OWL: uriPrefix = OWL.NAMESPACE; break; case PREFIX_SCHEMA: uriPrefix = SCHEMA.NAMESPACE; break; case PREFIX_REDLINK: uriPrefix = NS_REDLINK; break; case PREFIX_DBPEDIA: uriPrefix = NS_DBPEDIA; break; case PREFIX_FREEBASE: uriPrefix = NS_FREEBASE; break; case PREFIX_LOCAL: uriPrefix = HTTP_LOCALHOST; break; default: uriPrefix = ""; break; } Date created = new Date(input.readLong()); KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix, created); r.setId(id); return r; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiAnonResource serialized with writeBNode from a DataInput source * * @param input the source/*from w w w . j a v a 2s.co m*/ * @return the de-serialized KiWiAnonResource * @throws IOException */ public static KiWiAnonResource readBNode(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { String anonId = DataIO.readString(input); Date created = new Date(input.readLong()); KiWiAnonResource r = new KiWiAnonResource(anonId, created); r.setId(id); return r; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiBooleanLiteral serialized with writeBooleanLiteral from a DataInput source * * @param input the source//from w w w.j a va 2s. co m * @return the de-serialized KiWiBooleanLiteral * @throws IOException */ public static KiWiBooleanLiteral readBooleanLiteral(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { boolean content = input.readBoolean(); KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created); r.setId(id); return r; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiDateLiteral serialized with writeDateLiteral from a DataInput source * * @param input the source/*from ww w .j av a 2s . c o m*/ * @return the de-serialized KiWiDateLiteral * @throws IOException */ public static KiWiDateLiteral readDateLiteral(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { DateTime content = new DateTime(input.readLong(), DateTimeZone.forOffsetMillis(input.readInt())); KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created); r.setId(id); return r; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiDoubleLiteral serialized with writeDoubleLiteral from a DataInput source * * @param input the source/* ww w .ja v a2 s. c om*/ * @return the de-serialized KiWiDoubleLiteral * @throws IOException */ public static KiWiDoubleLiteral readDoubleLiteral(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { double content = input.readDouble(); KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created); r.setId(id); return r; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiIntLiteral serialized with writeIntLiteral from a DataInput source * * @param input the source/*from ww w. ja v a 2 s.co m*/ * @return the de-serialized KiWiIntLiteral * @throws IOException */ public static KiWiIntLiteral readIntLiteral(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { long content = input.readLong(); KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created); r.setId(id); return r; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiStringLiteral serialized with writeStringLiteral from a DataInput source * * @param input the source//from ww w .jav a 2s .c o m * @return the de-serialized KiWiStringLiteral * @throws IOException */ public static KiWiStringLiteral readStringLiteral(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { String content = readContent(input); byte langB = input.readByte(); String lang; switch (langB) { case LANG_EN: lang = "en"; break; case LANG_DE: lang = "de"; break; case LANG_FR: lang = "fr"; break; case LANG_ES: lang = "es"; break; case LANG_IT: lang = "it"; break; case LANG_PT: lang = "pt"; break; case LANG_NL: lang = "nl"; break; case LANG_SV: lang = "sv"; break; case LANG_NO: lang = "no"; break; case LANG_FI: lang = "fi"; break; case LANG_RU: lang = "ru"; break; case LANG_DK: lang = "dk"; break; case LANG_PL: lang = "pl"; break; default: lang = DataIO.readString(input); } KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created); r.setId(id); return r; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiTriple serialized with writeTriple from a DataInput source * * @param input the source//from w ww. j av a 2 s . com * @return the de-serialized KiWiTriple * @throws IOException */ public static KiWiTriple readTriple(DataInput input) throws IOException { KiWiTriple result = new KiWiTriple(); result.setId(input.readLong()); int mode = input.readByte(); if (mode == MODE_PREFIX) { String prefix = DataIO.readString(input); long sId = input.readLong(); String sUri = prefix + DataIO.readString(input); long sTime = input.readLong(); KiWiUriResource s = new KiWiUriResource(sUri); s.setId(sId); s.setCreated(new Date(sTime)); result.setSubject(s); result.setPredicate(readURI(input)); long oId = input.readLong(); String oUri = prefix + DataIO.readString(input); long oTime = input.readLong(); KiWiUriResource o = new KiWiUriResource(oUri); o.setId(oId); o.setCreated(new Date(oTime)); result.setObject(o); } else { result.setSubject((KiWiResource) readNode(input)); result.setPredicate(readURI(input)); result.setObject(readNode(input)); } result.setContext((KiWiResource) readNode(input)); result.setCreator((KiWiResource) readNode(input)); result.setDeleted(input.readBoolean()); result.setInferred(input.readBoolean()); result.setNewTriple(input.readBoolean()); result.setCreated(new Date(input.readLong())); long deletedAt = input.readLong(); if (deletedAt > 0) { result.setDeletedAt(new Date(deletedAt)); } return result; }
From source file:org.apache.nutch.crawl.CrawlDatum.java
public void readFields(DataInput in) throws IOException { byte version = in.readByte(); // read version if (version > CUR_VERSION) // check version throw new VersionMismatchException(CUR_VERSION, version); status = in.readByte();//from w w w . j a v a 2s.c o m fetchTime = in.readLong(); retries = in.readByte(); if (version > 5) { fetchInterval = in.readInt(); } else fetchInterval = Math.round(in.readFloat()); score = in.readFloat(); if (version > 2) { modifiedTime = in.readLong(); int cnt = in.readByte(); if (cnt > 0) { signature = new byte[cnt]; in.readFully(signature); } else signature = null; } if (version > 3) { boolean hasMetadata = false; if (version < 7) { org.apache.hadoop.io.MapWritable oldMetaData = new org.apache.hadoop.io.MapWritable(); if (in.readBoolean()) { hasMetadata = true; metaData = new org.apache.hadoop.io.MapWritable(); oldMetaData.readFields(in); } for (Writable key : oldMetaData.keySet()) { metaData.put(key, oldMetaData.get(key)); } } else { if (in.readBoolean()) { hasMetadata = true; metaData = new org.apache.hadoop.io.MapWritable(); metaData.readFields(in); } } if (hasMetadata == false) metaData = null; } // translate status codes if (version < 5) { if (oldToNew.containsKey(status)) status = oldToNew.get(status); else status = STATUS_DB_UNFETCHED; } }