Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2007 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.io;
 
 
An implementation of java.io.DataOutput that uses little-endian byte ordering for writing char, short, int, float, double, and long values.

Note: This class intentionally violates the specification of its supertype DataOutput, which explicitly requires big-endian byte order.

Author(s):
Chris Nokleberg
Keith Bottner
Since:
8.0
 
     implements DataOutput {

  
Creates a LittleEndianDataOutputStream that wraps the given stream.

Parameters:
out the stream to delegate to
 
     super(new DataOutputStream(Preconditions.checkNotNull(out)));
   }
 
   @Override public void write(byte[] bint offint lenthrows IOException {
     // Override slow FilterOutputStream impl
     .write(bofflen);
   }
 
   @Override public void writeBoolean(boolean vthrows IOException {
   }
 
   @Override public void writeByte(int vthrows IOException {
     ((DataOutputStream).writeByte(v);
   }

  

Deprecated:
The semantics of writeBytes(String s) are considered dangerous. Please use writeUTF(java.lang.String), writeChars(java.lang.String) or another write method instead.
 
   @Override public void writeBytes(String sthrows IOException {
     ((DataOutputStream).writeBytes(s);
   }

  
Writes a char as specified by java.io.DataOutputStream.writeChar(int), except using little-endian byte order.

Throws:
java.io.IOException if an I/O error occurs
 
   @Override public void writeChar(int vthrows IOException {
     writeShort(v);
   }

  
Writes a String as specified by java.io.DataOutputStream.writeChars(java.lang.String), except each character is written using little-endian byte order.

Throws:
java.io.IOException if an I/O error occurs
 
   @Override public void writeChars(String sthrows IOException {
     for (int i = 0; i < s.length(); i++) {
       writeChar(s.charAt(i));
     }
   }

  
Writes a double as specified by java.io.DataOutputStream.writeDouble(double), except using little-endian byte order.

Throws:
java.io.IOException if an I/O error occurs
  @Override public void writeDouble(double vthrows IOException {
    writeLong(Double.doubleToLongBits(v));
  }

  
Writes a float as specified by java.io.DataOutputStream.writeFloat(float), except using little-endian byte order.

Throws:
java.io.IOException if an I/O error occurs
  @Override public void writeFloat(float vthrows IOException {
    writeInt(Float.floatToIntBits(v));
  }

  
Writes an int as specified by java.io.DataOutputStream.writeInt(int), except using little-endian byte order.

Throws:
java.io.IOException if an I/O error occurs
  @Override public void writeInt(int vthrows IOException {
    .write(0xFF & v);
    .write(0xFF & (v >> 8));
    .write(0xFF & (v >> 16));
    .write(0xFF & (v >> 24));
  }

  
Writes a long as specified by java.io.DataOutputStream.writeLong(long), except using little-endian byte order.

Throws:
java.io.IOException if an I/O error occurs
  @Override public void writeLong(long vthrows IOException {
    byte[] bytes = Longs.toByteArray(Long.reverseBytes(v));
    write(bytes, 0, bytes.length);
  }

  
Writes a short as specified by java.io.DataOutputStream.writeShort(int), except using little-endian byte order.

Throws:
java.io.IOException if an I/O error occurs
  @Override public void writeShort(int vthrows IOException {
    .write(0xFF & v);
    .write(0xFF & (v >> 8));
  }
  @Override public void writeUTF(String strthrows IOException {
    ((DataOutputStream).writeUTF(str);
  }
New to GrepCode? Check out our FAQ X